I have stacked column series chart, the series are created at runtime. Everything works good, but I could not able to display the marker.
I was trying to set the marker template as in below
.
StackedColumnSeries series = new StackedColumnSeries { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Stretch, VerticalContentAlignment = VerticalAlignment.Stretch, XAxis = _xAxis, YAxis = _yAxis, Title = _graphDef[key].DisplayName, AutoGenerateSeries = true };
var xaml = @" <DataTemplate x:Key='FlowRateMarkerTemplate' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <TextBlock Margin='2' Text='{Binding Item.Value}' Foreground='White' FontSize='15' FontWeight='Bold' HorizontalAlignment='Center' /> </DataTemplate>"; var markerTemplate = XamlControlUtils.LoadXaml<DataTemplate>(xaml);
series.MarkerTemplate = markerTemplate;
I have tested that templates works fine if I hard code some value to Text of TextBlock instead of Item.Value
What could be problem?
Hello John,
Thank you for your email. I have been looking into the behavior that you have described and the reason for it is that the Item property of the DataContext of the DataTempalte is an object that is generated at runtime, by the GroupBy. If you use that code and open the output, you should be able to see a binding error, similar to the following:
System.Windows.Data Error: 40 : BindingExpression path error: 'Value' property not found on 'object' ''73f8b6d8-c974-42dc-8c46-e2691e60e333__proxy' (HashCode=55671433)'. BindingExpression:Path=Item.Value; DataItem='DataContext' (HashCode=27545396); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
In order to create a template for the marker and show the value of the current column, you can use the SeriesCreated event of the StackedColumnSeries and set the e.MarkerTemplate. In the event you can use the sender to get the StackedFragmentSeries that is generated and you can set the path of the binding of the Text to Item + the ValueMemberPath to the generated series. Here is how you can do that:
series.SeriesCreated += (ss, ee) =>
{
StackedFragmentSeries ser = (StackedFragmentSeries)ss;
var xaml = @"
<DataTemplate x:Key='FlowRateMarkerTemplate'
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<TextBlock Margin='2' Text='{Binding Item." + ser.ValueMemberPath + @"}'
Foreground='White' FontSize='15' FontWeight='Bold'
HorizontalAlignment='Center' />
</DataTemplate>";
var markerTemplate = XamlReader.Parse(xaml) as DataTemplate;
ee.Title =
ee.MarkerTemplate = markerTemplate;
};
I have created a sample application for you, that shows how you can use this event.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
cool. Thanks
Thank you for your reply. I am very glad that the approach I have suggested helped solving your issue. Please let me know if you need any further assistance on the matter.