Hi,
I am looking to bind the colours of specific countries to properties in a view model (e.g. country of departure and country of arrival). Information loaded via shapefiles and a converter into a GeographicShapeControlSeries. All examples i've seen either use random colours, or some sort of gradient based on a property of the map source, such as temperature.
For my case, I applied a style based on the Geographic Shape Control Series example from the sample browser, which exposes the RootElement Path, i have added the country name to the tag of this element. Currently the only approach i have found to work is to subscribe to the loaded event of this Path and check in code-behind if the tag is either the desired departure or arrival country names. This isn't ideal; i've been running into difficulty exposing the collection of countries so i can bind the Fill Dependency Property to a Brush object in the ViewModel. The closest i came was a UIElementCollection of the Canvas, but could not get any further.
It feels like i'm missing something obvious to achieve my goal of binding specific country colours, possibly something to do with Shape Style Selectors? Any advice on how to proceed would be greatly appreciated.
Thanks.
Hello Frazer,
Thank you for your post. I have been looking into it and I created a sample project for you with the functionality you want. Basically I set the XamGeographicMap’s ShapeStyleSelector to be a ConditionalStyleSelector. This way I was able to apply different Styles based on a Field’s Value(in my case Code). Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.
Thanks for the reply. While this does allow me to set the style based on a field's value initially, i ran into trouble with this example trying to bind the ComparisonValue of the EqualToConditionalStyleRule to a country code in a View Model. Ideally the coloured countries would be able to change based on different View Models or property changes. Do you have any suggestions how to achieve this? If possible, i would be looking for a solution that allows for the possibility of binding the style to potentially multiple properties (for example, a list of destination countries for one origin country, or something to that effect).
Thanks,
Frazer
I can say that the only way to bind the ComparisonValue of the EqualToConditionalStyleRule is to set the Binding's Source Property, because this element is not a visual element and it is not part of the Visual Tree and it's doesn't inherit from the DataContext. Also you can log a product idea for the ability to bind this value via the DataContext here:
http://ideas.infragistics.com/
If this suggestion doesn't satisfies all your needs I can suggest you use your approach where you handle the Paths' Loaded events.
Thanks for the replies.
Best i could come up with was to establish the binding to the style selector in code-behind each time either the destination or arrival country collections changed. Slows down noticeably when zooming, but as it remains fast for hovering, it seems good enough.
I did have another question though. I've been trying to set up a ShapeFileConverter to accept files from another project within the same solution, something like this:
<ig:ShapefileConverter x:Key="shapefileConverter" ShapefileSource="pack://application:,,,/targetassembly;component/Maps/file.shp" DatabaseSource="pack://application:,,,/targetassembly;component/Maps/file.dbf">
The preview shows that it is able to find the files in question, but when i run the application the content is empty, and when i delve into the ShapeFileConverter, i find it has no items within it. This works when the source folder and files are local. Can you suggest a way to enable this loading from another project, or offer advice on what i might be doing wrong with my current approach?
I have been looking into your question and I can say that currently it is not possible to use Relative URL's on the ShapefileConverter, so my suggestion is follow the approach with the URLConverter and convert the relative URLs to absolute ones. Please let me know if you have further questions on this matter.
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
Yes thank you, the answers pointed me in the right direction.