Bober02 Posted July 26, 2010 Report Posted July 26, 2010 Hey there, Another quick question. I want to bind a data trigger to PointPresenter (or anything that actually displays point as a dot on the chart). I simply don't know what actually displays a point... I want to know the equivalent of DataGrid's CellValuePresenter. Quote
JuanC Posted July 27, 2010 Report Posted July 27, 2010 I am assuming because of the question that you are referring to a scatter/line/curve chart, note that templating a chart is a little more involved than templating a datagrid because of the different plot styles (bar, line, pie, scatter, etc.) as well as the number of properties these elements support. To change the template used in a marker you would use the following template <DataTemplate x:Key="MarkerRect"> <Rectangle x:Name="marker" Width="{Binding Path=Width}" Height="{Binding Path=Height}" Fill="Purple" Stroke="{Binding Path=MarkerStroke}" StrokeThickness="{Binding Path=MarkerStrokeThickness}" Opacity="{Binding Path=MarkerOpacity}"/> <DataTemplate.Triggers> <DataTrigger Binding="{Binding Path=Dimmed}"> <DataTrigger.Value> <sys:Boolean>True</sys:Boolean> </DataTrigger.Value> <Setter Property="Opacity" Value="0.25" /> </DataTrigger> </DataTemplate.Triggers> </DataTemplate> And the following code chart1.AllSeries.Marker.Template = (DataTemplate) FindResource("MarkerRect"); Note that you can also set the template in XAML but it takes a couple more lines, in the template I changed the Rectangle Fill to Purple so that you can easily check if the template is being applied (it would normally be bound to MarkerFill to honor the Series.Fill API). This template's data context is a ChartFX class that exposes a property called DataItem that points to the CLR object you passed to ChartFX. This will allow you to change visual attributes based on your own properties. JuanC Quote
Bober02 Posted July 27, 2010 Author Report Posted July 27, 2010 Thanks for reply firstly. Just to make it clear, if I have a property Highlighted on each DataItem, which is either true or false, should I modify the above in the following way: Set another data trigger with Path=DataItem.Highlighted and as value = true I will add setter changing Fill="Gold" in order to get golden markers for all points which have highlighted property set to true or am I going completely wrong direction? Cheers in advance. (Sorry but posting xaml resulted in my code disappearing as forum treats it as xml or sth...) Quote
Bober02 Posted July 28, 2010 Author Report Posted July 28, 2010 Also, the data template changes contentPresenter properties, which does not include Fill etc. So how can I reference the above Rectangle (x:key marker) and change its properties using data templates triggers triggers? Quote
JuanC Posted July 28, 2010 Report Posted July 28, 2010 Yes, you can use DataItem.YourOwnPropertyGoesHere in triggers, to change rectangle properties you have to use TargetName as follows <DataTrigger Binding="{Binding Path=DataItem.HasDiscount}"> <DataTrigger.Value> <sys:Boolean>True</sys:Boolean> </DataTrigger.Value> <Setter TargetName="marker" Property="Fill" Value="Gold" /> </DataTrigger> JuanC Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.