The following code applies the ConditionalStyleSelector to the GeographicShapeSeries:
<ig:XamGeographicMap.Series> <ig:GeographicShapeSeries ItemsSource="{StaticResource shapeFileSource}" ShapeMemberPath="Points"> <ig:GeographicShapeSeries.ShapeStyleSelector> <ig:ConditionalStyleSelector> <ig:ConditionalStyleSelector.Rules> <ig:EqualToConditionalStyleRule ValueMemberPath="Fields[REGION]" ComparisonValue="Asia" StyleToApply="{StaticResource shapeAsiaStyle}" /> <ig:EqualToConditionalStyleRule ValueMemberPath="Fields[REGION]" ComparisonValue="Australia" StyleToApply="{StaticResource shapeAustraliaStyle}" /> </ig:ConditionalStyleSelector.Rules> </ig:ConditionalStyleSelector> </ig:GeographicShapeSeries.ShapeStyleSelector> </ig:GeographicShapeSeries> </ig:XamGeographicMap.Series>
Now my question is that How can I make these conditional rules dynamic, let's say I have an ObservableCollection of ConditionalStyleRule:
public class MyViewModel { public ObservableCollection<ConditionalStyleRule> Rules { get; set; } //.... }
Now how can I bind these collection to view, I mean Is it possible to have something like this:
<ig:GeographicShapeSeries.ShapeStyleSelector> <ig:ConditionalStyleSelector> <ig:ConditionalStyleSelector.Rules DataContext="{Binding Rules}"> </ig:ConditionalStyleSelector.Rules> </ig:ConditionalStyleSelector> </ig:GeographicShapeSeries.ShapeStyleSelector>
Hello,
Currently, the Rules collection of the ConditionalStyleSelector is not bind-able, as it is not a DependencyProperty. Normally, to work around this, I would recommend that you define your own custom ConditionalStyleSelector and create a DependencyProperty that takes a collection of ConditionalStyleRule, but ConditionalStyleSelector’s ultimate base class is StyleSelector, which does not derive from DependencyObject, and so this cannot be done either.
As such, I would now recommend that you define a custom GeographicShapeSeries. Doing this will allow you to define a DependencyProperty for your rules, and when this property changes, you can set the ConditionalStyleSelector and its Rules collection to the rules that you define in your bound collection.
I am attaching a sample project that demonstrates a binding like the above. I hope this helps you. Note, to run the sample you will need to modify the URI's of the ShapefileConverter in the XAML, as relative URI's are not supported.
Please let me know if you have any other questions or concerns on this matter.
XamGeoMapShapeStyleSelectorDemo.zip
Hello, Thanks it's really great, Is it possible to have the property for GeographicSymbolSeries?
Hello Sirwan,
It appears that you have recently asked a very similar question at another forum thread that I have very recently answered with a sample project demonstrating how this can be achieved with the GeographicSymbolSeries. I would recommend that you take a look.