Dela via


MapControl.StyleSheet Property

Definition

Gets or sets an object that defines the style of the map control.

public:
 property MapStyleSheet ^ StyleSheet { MapStyleSheet ^ get(); void set(MapStyleSheet ^ value); };
MapStyleSheet StyleSheet();

void StyleSheet(MapStyleSheet value);
public MapStyleSheet StyleSheet { get; set; }
var mapStyleSheet = mapControl.styleSheet;
mapControl.styleSheet = mapStyleSheet;
Public Property StyleSheet As MapStyleSheet

Property Value

An object that defines the style of the map control.

Windows requirements

Device family
Windows 10 Creators Update (introduced in 10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v4.0)

Examples

The following example sets the StyleSheet property by using one of the provided styles through the static MapStyleSheet.RoadDark method.

myMap.StyleSheet = MapStyleSheet.RoadDark();

Custom map styles can be defined in JSON and loaded through the MapStyleSheet.ParseFromJson method. They can optionally combined with a provided style.

A scalable way to do this is to create a file named MyStyle.json in the Assets folder of a UWP application. Make sure that its Build Action property is set to Content.

{
    "version": "1.*",
    "elements":{
        "water":{
            "fillColor":"#FF000000"
        }
    }
}

Add the following code to the application which has a MapControl named myMap.

Uri uri = new Uri("ms-appx:///Assets/MyStyle.json");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);
string jsonText = await FileIO.ReadTextAsync(file);
myMap.StyleSheet = MapStyleSheet.Combine(new List<MapStyleSheet>
{
    MapStyleSheet.RoadLight(),
    MapStyleSheet.ParseFromJson(jsonText)
});

Applies to