Hi,
I added xamMap to my application and I set colors for map elements in my code behind on Loaded event depending on some character values. I would like to have a legend of my map which shows those character values. As far as understand, I have to use ValueScale with Distribution Scale. But I don't know where I should add a converter. Do you have any sample ?
Thanks,
Ed
Hello Ed,
Thank you for your post. I have been looking into your requirement and I am attaching a sample application(xamMapLegend.zip) where I show how to create a legend for your XamMap control.
If you need any further assistance on this matter, feel free to ask.
Yanko,
Thanks for the sample, but it's not what I would like to display. I would like, for example, set a color for each state to red or blue based on presidential election result and display a legend - 'Rep' label near the red box and 'Dem' label near the blue box. I am able to set colors in my code behind:
private void mapControl_Loaded(object sender, System.Windows.RoutedEventArgs e) { SolidColorBrush repBrush = new SolidColorBrush(Colors.Red); SolidColorBrush demBrush = new SolidColorBrush(Colors.Blue);
MapViewModel vm = (MapViewModel)this.DataContext; MapLayer layer = this.mapControl.Layers[0]; foreach (MapElement element in layer.Elements) { string caption = (string)element.GetProperty("Caption"); if (vm.statesData.Contains(caption)) { if ((string)vm.statesData[caption] == "R") element.Fill = repBrush; else element.Fill = demBrush; } } }
It works fine. Then in XAML file I set ValueScale:
<ig:MapLayer.ValueScale> <ig:DistributionScale IsAutoRange="False" ValueStopCount="2" ValueStops="0 1"/> </ig:MapLayer.ValueScale>
Then I set MapColorSwatchPane:
<ig:MapColorSwatchPane Margin="15" DisplayMode="Sample" LayerName="statesLayer" ig:XamDock.VerticalDockAlignment="Bottom" ig:XamDock.HorizontalDockAlignment="Right" ig:XamDock.Edge="InsideRight">
and I got a legend with 0 on top of red box and 1 on top of blue box. How can I set custom labels in the legend ?