So I am working on a program that on recieving a series of values turns them into a Point Collection that then gets plotted into a LineGraph in a Chart. My problem is that when creating the legend using the Char.LegendContent with a DataTemplate, instead of using the DataTemplate the legend is automatically generated with the default values, unless I'm debugging and remove and insert again the DataTemplate, in which case its displayed correctly.
Does anyone know how to fix it? I have also tried hiding single legends as one of the graph is made up of multiple line graph do display multiple colors but couldn't manage it.
Here is my code
<DataTemplate DataType="{x:Type viewModels:PlotResultWithTest}">
<wpf:Chart BottomTitle="{Binding XAxisTitle}" LeftTitle="{Binding YAxisTitle}">
<wpf:Chart.LegendContent>
<wpf:LegendItemsPanel>
<wpf:LegendItemsPanel.Resources>
<DataTemplate x:Key="InteractiveDataDisplay.WPF.LineGraph">
<StackPanel Orientation="Horizontal" Visibility="{Binding Path=Description, Converter={StaticResource DescriptionToVisibility}}">
<Line Width="15" Height="15" X1="0" Y1="0" X2="15" Y2="15" Stroke="{Binding Path=Stroke}" StrokeThickness="2"/>
<TextBlock Margin="5 0 0 0" Text="{Binding Path=Description}"/>
</StackPanel>
</DataTemplate>
</wpf:LegendItemsPanel.Resources>
</wpf:LegendItemsPanel>
</wpf:Chart.LegendContent>
<Interactions:Interaction.Behaviors>
<behaviors:ChartBoundsBehavior/>
</Interactions:Interaction.Behaviors>
<wpf:Chart.ContextMenu>
<ContextMenu DataContext="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
<MenuItem Header="Reset" Command="{Binding ChartBounds.EnableAutoFitCommand}" />
</ContextMenu>
</wpf:Chart.ContextMenu>
<Grid>
<controls:PolygonGraph Points="{Binding MinMaxValues, Mode=OneTime}" Stroke="{x:Null}" Fill="Transparent"/>
<wpf:LineGraph Points="{Binding FlTestValues, Mode=OneTime}" Description="{Binding FlTestDescription}" Stroke="{StaticResource FlightTestColor}" StrokeThickness="2" Visibility="{Binding FlTestVisible, Converter={StaticResource BoolToVisibility}}"/>
<controls:PolygonGraph Points="{Binding FlTestBoundValues, Mode=OneTime}" Description="FT Tolerance" Stroke="Gray" StrokeThickness="1" Visibility="{Binding FlTestBoundsVisible, Converter={StaticResource BoolToVisibility}}">
<controls:PolygonGraph.Fill>
<SolidColorBrush Color="Blue" Opacity="0.03"/>
</controls:PolygonGraph.Fill>
</controls:PolygonGraph>
<wpf:LineGraph Points="{Binding MasterValues, Mode=OneTime}" Description="{Binding MasterDescription}" Stroke="{StaticResource MasterColor}" StrokeThickness="2" Visibility="{Binding MasterVisible, Converter={StaticResource BoolToVisibility}}"/>
<controls:PolygonGraph Points="{Binding MasterBoundValues, Mode=OneTime}" Description="Master Tolerance" Stroke="Gray" Visibility="{Binding MasterBoundsVisible, Converter={StaticResource BoolToVisibility}}">
<controls:PolygonGraph.Fill>
<SolidColorBrush Color="Magenta" Opacity="0.03"/>
</controls:PolygonGraph.Fill>
</controls:PolygonGraph>
<ItemsControl ItemsSource="{Binding ValuesList}" Visibility="{Binding ResultVisible, Converter={StaticResource BoolToVisibility}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<wpf:LineGraph Points="{Binding FinalValues, Mode=OneTime}" StrokeThickness="2" Stroke="{Binding GoodValues, Converter={StaticResource ColorConverter}}" Visibility="{Binding ResultVisible, Converter={StaticResource BoolToVisibility}}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<wpf:LineGraph Points="{Binding Values, Mode=OneTime}" Description="{Binding Header}" Stroke="{StaticResource RecordingColor}" StrokeThickness="2" Visibility="{Binding ResultVisible, Converter={StaticResource BoolToVisibility}}"/>
</Grid>
</wpf:Chart>
</DataTemplate>