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}" />
}"/>
Hi Stefan,
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
Hello 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.
Thanks! I updated your version and created a new from yours with Docking.
The same exception is happening now as well.
Run the application and then try dock the chart panel. doesn't work!
if you comment the xamDataChart1_Loaded event source code, it's work fine.
If you can find a work around for that, I have to deploy this new version as soon as possible.
Jorge Arteiro