SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
Hi,
I’m experimenting with the LegendModifier and want to control which RenderableSeries are shown via the “LegendItemTemplate” approach. The idea is to add a specific tagging class to the RenderableSeries.DataSeries.Tag and use the content inside the LegendItemTemplate which I define in the Window.Resouces.
The tagging Class:
public class DataSeriesTag
{
public string LegendText { get; set; }
public bool ShowLegend { get; set; }
}
The LegendItemTemplate:
<Window.Resources>
<Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
<!--<CheckBox Width="16" Margin="5,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
IsChecked="{Binding RenderableSeries.IsVisible, Mode=TwoWay}"
Visibility="{Binding RenderableSeries.DataSeries.Tag.ShowLegend, Converter={dxmvvm:BooleanToVisibilityConverter}}" />-->
<s:PointMarker Grid.Column="1" Margin="5,0,0,0" Width="40" Height="10" VerticalAlignment="Center" HorizontalAlignment="Center"
DataContext="{Binding RenderableSeries}"
DeferredContent="{Binding LegendMarkerTemplate}"
Visibility="{Binding ShowSeriesMarkers, RelativeSource={RelativeSource AncestorType=s:SciChartLegend}, Converter={dxmvvm:BooleanToVisibilityConverter}}" />
<TextBlock Margin="5,0,5,0"
Grid.Column="2"
HorizontalAlignment="Left"
Text="{Binding RenderableSeries.DataSeries.Tag.LegendText}" />
</Grid>
</DataTemplate>
</Window.Resources>
As long as I declare the SciChartSurface.ChartModifier in XAML, it works perfect.
The proplem raises when I bind the ModifierGroup to a ViewModel Property and try to build the LegendModifier there. How can I assign the LegendItemTemplate in the ViewModel?:
legendModifier = new LegendModifier(){
ShowLegend = true,
ShowVisibilityCheckboxes = false,
LegendItemTemplate = ??????
};
TheModifiers.ChildModifiers.Add(legendModifier);
Kind regards
Martin
Something was cut for the LegendItemTemplate, I try again
<DataTemplate x:Key="SciChartLegendItemTemplate" DataType="s:SeriesInfo">
<Grid Visibility="{Binding RenderableSeries.DataSeries.Tag.ShowLegend, Converter={dxmvvm:BooleanToVisibilityConverter}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!--<CheckBox Width="16" Margin="5,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
IsChecked="{Binding RenderableSeries.IsVisible, Mode=TwoWay}"
Visibility="{Binding RenderableSeries.DataSeries.Tag.ShowLegend, Converter={dxmvvm:BooleanToVisibilityConverter}}" />-->
<s:PointMarker Grid.Column="1" Margin="5,0,0,0" Width="40" Height="10" VerticalAlignment="Center" HorizontalAlignment="Center"
DataContext="{Binding RenderableSeries}"
DeferredContent="{Binding LegendMarkerTemplate}"
Visibility="{Binding ShowSeriesMarkers, RelativeSource={RelativeSource AncestorType=s:SciChartLegend}, Converter={dxmvvm:BooleanToVisibilityConverter}}" />
<TextBlock Margin="5,0,5,0"
Grid.Column="2"
HorizontalAlignment="Left"
Text="{Binding RenderableSeries.DataSeries.Tag.LegendText}" />
</Grid>
</DataTemplate>
Please login first to submit.