I have this GeographicShapeSeries component and I would like the add a TextBlock to the DataTemplate but I'm getting a cast exception when I try
GeographicShapeSeries series = new GeographicShapeSeries() { ItemsSource = data, MarkerTemplate = new DataTemplate(), ShapeMemberPath = "Points", Brush = brush, BorderBrush = Brushes.MediumBlue, ToolTip = "DæknigsGrad " + s.properties.maxDaekningTal + " PostBy " + s.properties.POSTBYNAVN + " Post nr " + s.properties.POSTNR_TXT
};
Hello Thomas,
From your code-snippet, I am little unsure why you are seeing a cast exception, but I am attaching a sample project to demonstrate how you can modify the MarkerTemplate of a GeographicShapeSeries in the Infragistics for WPF XamGeographicMap. I hope this helps you.
Please note that in the sample, the .shp and .dbf files are using an absolute URI as that is what is expected for the ShapeDataSource, and so you will need to change them to the file paths on your machine accordingly.
Please let me know if you have any other questions or concerns on this matter.
XamGeoMapMarkerTemplateDemo.zip
Hi Andrew
How can set the content property in the textblok
It is difficult for me to say why the “postnr” is not working in this case without knowing what binding path you are passing in.
What I can say, is that the data context of the TextBlock within your MarkerTemplate is an Infragistics.Controls.Charts.DataContext object, and so this is what you will be binding to by using the SetBinding method. This object has an “Item” property that returns the underlying data item for the shape in the GeographicShapeSeries, and so if you are looking to bind to your data item’s properties, you will want to pass in “Item.<X>” where <X> is the property on your data item.
PostNr (zipcode) is just a string and I know that comes from reading som json, It works when i pass it to tooltips
Are you looking to just set the Text of the TextBlock in this case, or are you looking to bind it? I ask, as SetBinding will be binding that Text, and is essentially the same as writing the following in XAML, where “ABC” would be what is contained in your postnr variable:
<DataTemplate> <TextBlock Text="{Binding ABC}" /> </DataTemplate>
If this is not what you are trying to do and you are only looking to set the text value rather than bind it, I would recommend that you use the SetValue method on your FrameworkElementFactory mentioned in another response above rather than using the SetBinding method.
You have mentioned that this is working for your Tooltip, but in your original update, it looks like you are only setting the tooltip on your series and not binding it, which is why I am under the impression that you are really looking to use SetValue instead of SetBinding.
SetValue worked. Can you tell me why I cannot set the BackGround color of the shape I have set it to Brush White but it keeps showing up dark grey
I am attaching a modified sample project in which I am setting the Brush and Outline properties on the GeographicShapeSeries and it is working correctly. This should reflect upon the series, and it is doing so in the sample project.
Would it be possible for you to please provide some additional information on which parts are showing up dark-grey for you? Perhaps you can provide a screenshot of the behavior you are seeing?
4113.XamGeoMapMarkerTemplateDemo.zip