I am trying write a template to Legend control. I have version 10.3, .net 4, xamDataChart, with a few line series.
My Legend is Horizontal and I want this to wrap when i have many items(series). Something thing like tab control showing multiple lines. Is this possible? I have to have my Legend at the Top.
I have custom Legend template and Legendtemplateitem, but it's not working. I just comented the ScrowViewer and replace this for a WrapPanel.
Any Help is welcome.
<ControlTemplate x:Key="xamDataChartLegendTemplate" TargetType ="Charts:Legend">
<Grid>
<Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="4" Background="{TemplateBinding Background}">
<Grid Margin="{TemplateBinding Padding }">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ContentPresenter Grid.Row="0" Content="{TemplateBinding Content}" />
<!--<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="auto" VerticalScrollBarVisibility="auto" BorderThickness="0" Background="Transparent">-->
<WrapPanel Orientation="Horizontal" Grid.Row="1">
<ContentPresenter Grid.Row="1" x:Name="ContentPresenter" />
</WrapPanel>
<!--</ScrollViewer>-->
</Grid >
</Border>
<Border IsHitTestVisible="False" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="Transparent" CornerRadius="4" Background="{StaticResource GenericOverlay}" />
</Grid>
</ControlTemplate>
<
DataTemplate x:Key="xamDataChartCustomLegendItemTemplate">
.Visibility}">
.LegendItemBadgeTemplate}" />
}"/>
Hello,
Thank you for your post. I have been looking into it, but I wasn’t able to reproduce your behavior, so if this is still an issue for you, could you please send me an isolated sample project, where this is reproduced, so I can investigate it further for you.
Looking forward for your reply.
Hi Stefan,
I just upgrade this application from version 10.3 to 11.2.
The code still working but when I try dock the pane with the chart, i got this exception: "Specified element is already the logical child of another element. Disconnect it first."
If I comment out this code below, it works.
Can you help me with that?
This is my code:
private void MainDataChart_Loaded(object sender, RoutedEventArgs e) { // Change Legend to show multiple lines ContentPresenter cp = Utilities.GetDescendantFromName(xmLegend, "ContentPresenter") as ContentPresenter; if (cp != null) { StackPanel sp = cp.Content as StackPanel; if (sp != null) { WrapPanel wp = new WrapPanel() {Orientation = System.Windows.Controls.Orientation.Horizontal}; int count = sp.Children.Count; for (int i = 0; i < count; i++) { ContentControl cc = sp.Children[0] as ContentControl; sp.Children.Remove(sp.Children[0] as ContentControl); if (cc != null) wp.Children.Add(cc); } cp.Content = wp; } } }
I have attached a sample project showing that.
I want the legend to show all the series data.
Any help is welcome.
Regards,
Jorge Arteiro