The Map
class’s ColorMode
property allows you to change the tonal palette of the map from a light palette, suitable for daytime viewing, to a dark pallet, suitable for night time viewing or low light conditions.
The dark mode/light mode menu item in the MapView
page toggles the Map control’s ColorMode
property from light to dark. The Map control’s ColorMode
property is bound to the MapViewMode
l’s MapColorMode
, as shown:
<m:Map x:Name="map"
...
ColorMode="{Binding MapColorMode, Mode=TwoWay}"
...
</m:Map>
An AppBarMenuItem
is bound to the viewmodel’s ToggleColorModeCommand
, like so:
<u:AppBarMenuItem
x:Name="toggleColorModeMenuItem"
Command="{Binding ToggleColorModeCommand}"
Text="color mode placeholder" />
The command is initialized within the viewmodel’s constructor. When executed, the command sets the viewmodel’s MapColorMode
, as shown:
toggleColorModeCommand = new DelegateCommand(
obj => SetColorMode(mapColorMode == MapColorMode.Light
? MapColorMode.Dark : MapColorMode.Light));
For more information on the AppBarMenuItem
see Chapter 8, “Taming the Application Bar.”
3.144.9.124