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; } } }
This is my leged template:
<ControlTemplate x:Key="xamDataChartLegendTemplate" TargetType="Charts:Legend">
<Grid Margin="{TemplateBinding Padding}">
<ContentPresenter x:Name="ContentPresenter" />
<Border IsHitTestVisible="False" BorderThickness="{TemplateBinding BorderThickness}"BorderBrush="Transparent" CornerRadius="4" Background="{StaticResource GenericOverlay}" />
Hello Jorge,
The StackPanel is applied in the source code of the XamDataChart and the whole code expects a StackPanel, so when you change it run time it is expected that, when the control loads again with another instance, set as panel, it could rise an exception, so I can suggest you either not use this approach, because in your scenario the control loads multiple times or wait till the product idea, about choosing what panel should hold the items, gets implemented.
Thanks for your support. Like I said as well, if you put a breakpoint xamDataChart1_Loaded in DatChart.xaml.cs, you can see that the exception is not in my code, it's after it leave the xamDataChart1_Loaded event. I am checking if it's not null before make any change again.(if (sp != null)).
when you say:"the default StackPanel is applied internally in code". Is it a infragistics control code? if it's replaced, why is breaking the code? should be usig the default again and not breaking.
What you think?
It's a 24/7 critical application!
Regards,
Jorge
As I said before, the deafult StackPanel is applied internally in code when the XamDataChart Loads. If you change it, it will work till the control's Loaded event is fired again and then it rises an exception, so I can suggest yo uwait till the product idea for the ItemContainer gets implemented.
If you look my code, I have changed the loaded event to support the second call when you dock.
It's works with version 10.3 until now. It's something with dockmanager and the template that we are using.
The second call to loaded event is not changing anything on the content presenter.
Any idea? I really need help on that.
Cheers, Jorge
// 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 been looking into your sample and I can say that the approach I have suggested works correctly if the XamDataChart is loaded only once, becasue the setting od the StackPanel is made internaly by code. In your case it loads everytime it is docked/undocked. I also logged a Product Idea for choosing the Legend's ItemPanel which won't casue any exceptions.