Hello,
I'm extending your RadCartesianChart to provide Legend support. Creating them manually is not an option for us (all series are dynamic and mapped to signals configured by user), and we don't want to create user control which will contain RadCartesianChart and Legends because we need to access all properties of RadCartesianChart directly on our control because they will be configurable in external tool.
The problem I've encountered is that RadCartesianChart ignores this template and just takes the width and height of the whole control,
and not the size which was given in this template. In the end I always get legend over the graph area as if I were using Grid for layouting.
How can I resolve this?
Control template I've created for my control is this:
<ControlTemplate TargetType="{x:Type CartesianChart:ConfigurableCartesianChart}">
<DockPanel LastChildFill="True">
<Grid Width="{TemplateBinding LegendWidth}"
Height="{TemplateBinding LegendHeight}"
DockPanel.Dock="{TemplateBinding LegendPosition}"
Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Margin="2" VerticalAlignment="Center" Text="{TemplateBinding LegendTitle}" />
<ItemsControl ItemsSource="{Binding Series}" Grid.Row="1">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid DataContext="{Binding Configuration}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Line Width="12" Height="12" X1="0" Y1="6" X2="12" Y2="6"
Stroke="{Binding SeriesStrokeColor}" StrokeThickness="2"
VerticalAlignment="Center" MaxWidth="100" Margin="5" />
<TextBlock Grid.Column="1" Text="{Binding DisplayName}"
VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<!--from CartesianChart template-->
<Border x:Name="layoutRoot"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<Grid>
<ContentPresenter x:Name="emptyContent"
ContentTemplate="{TemplateBinding EmptyContentTemplate}"
Content="{TemplateBinding EmptyContent}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
IsHitTestVisible="False"
Visibility="Collapsed"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Canvas x:Name="adornerContainer"
Background="Transparent"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Canvas x:Name="labelContainer"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Canvas x:Name="renderSurface"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Border x:Name="plotAreaDecoration" Style="{TemplateBinding PlotAreaStyle}"/>
</Canvas>
</Canvas>
</Canvas>
</Grid>
</Border>
</DockPanel>
</ControlTemplate>
I'm extending your RadCartesianChart to provide Legend support. Creating them manually is not an option for us (all series are dynamic and mapped to signals configured by user), and we don't want to create user control which will contain RadCartesianChart and Legends because we need to access all properties of RadCartesianChart directly on our control because they will be configurable in external tool.
The problem I've encountered is that RadCartesianChart ignores this template and just takes the width and height of the whole control,
and not the size which was given in this template. In the end I always get legend over the graph area as if I were using Grid for layouting.
How can I resolve this?
Control template I've created for my control is this:
<ControlTemplate TargetType="{x:Type CartesianChart:ConfigurableCartesianChart}">
<DockPanel LastChildFill="True">
<Grid Width="{TemplateBinding LegendWidth}"
Height="{TemplateBinding LegendHeight}"
DockPanel.Dock="{TemplateBinding LegendPosition}"
Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Margin="2" VerticalAlignment="Center" Text="{TemplateBinding LegendTitle}" />
<ItemsControl ItemsSource="{Binding Series}" Grid.Row="1">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid DataContext="{Binding Configuration}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Line Width="12" Height="12" X1="0" Y1="6" X2="12" Y2="6"
Stroke="{Binding SeriesStrokeColor}" StrokeThickness="2"
VerticalAlignment="Center" MaxWidth="100" Margin="5" />
<TextBlock Grid.Column="1" Text="{Binding DisplayName}"
VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<!--from CartesianChart template-->
<Border x:Name="layoutRoot"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<Grid>
<ContentPresenter x:Name="emptyContent"
ContentTemplate="{TemplateBinding EmptyContentTemplate}"
Content="{TemplateBinding EmptyContent}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
IsHitTestVisible="False"
Visibility="Collapsed"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Canvas x:Name="adornerContainer"
Background="Transparent"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Canvas x:Name="labelContainer"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Canvas x:Name="renderSurface"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Border x:Name="plotAreaDecoration" Style="{TemplateBinding PlotAreaStyle}"/>
</Canvas>
</Canvas>
</Canvas>
</Grid>
</Border>
</DockPanel>
</ControlTemplate>