Hi (Graham? ;),
I'm trying to get this working.
<DataTemplate x:Key="CircleMarkerTemplate"> <Ellipse x:Name="myEllipse" Effect="{StaticResource MarkerEffect}" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Fill="Red" Stroke="Black" StrokeThickness="1" MinWidth="7" MinHeight="7" /> <DataTemplate.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MonthlyCharges}}, Path=Item.IsSelected}" Value="True"> <Setter Property="Fill" TargetName="myEllipse" Value="Cyan" /> </DataTrigger> </DataTemplate.Triggers> </DataTemplate>
I have added an IsSelected property to my MonthlyCharge object and I'm trying to change the color of the marker based on this bool property, not working at the moment as the FindAncestor is only finding a ContentControl ... I've used FindAncestor like this loads of times but in this scenario it's completely failing. Any ideas?
FindAncestor is going to look for containing elemenrs in the tree, so unless MonthlyCharges is a container, its not going to help.
If MonthlyCharges is a datacontext, say, on the window then you could look for an ancestor of type Window and bind to its DataContext property, or maybe an attached property, etc. Be aware, though, that you pay somewhat of a performance penalty for using this kind of search based binding.
Another option for doing something like this is to bind against something on the Item for the marker, which is accessible to you in the DataContext as Item, so you can just do something like {Binding IsSelected} from the marker template.
Alternatively, you can store something in an attached property on the series. Which is accessible to you in the data context also. So, for example if you had an attached property ChartProperties.IsSelected defined in your local namespace, you could do something like this:
{Binding Series.(local:ChartProperties.IsSelected)}
etc.
The downside of using this approach for selection though, as I mentioned in the other thread, is that the chart doesn't consider any individual marker as essential to display. If you have a small number of points, this is no issue. But as you start to have mass amounts of points, the chart may choose to not display markers that are wholly or even partially occluded by other markers. So, if you are selecting a marker in a grid, and expect to have a visual representation of where it is in the chart, its better to overlay some visual on top of the chart to display were the point is, which is the strategy I used in the sample I posted in your other thread.
However, if you don't have a large number of points, amending the marker template like this is a fine option.
-Graham
Hey Graham,
Indeed, this is working great. I've used Ingragistics DataGrid a lot and the old Chart but still getting used to the APIs ... man they are BIG!!!!
Anyway, got this all working now (I need to show folks that the controls will work for our project) so I've not had the time to implement the overlays as you suggested, I've only got a bit more time to convince them to go Infragisitcs ...
Thanks for all your help, much apprecited I think I have enough to get the go ahead on the buy ...
Glad I could help! Let me know if you have any more questions.