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 have attached a sample project showing that.
I want the legend to show all the series data.
Any help is welcome.
Regards,
Jorge Arteiro
Hello Jorge,
I have been looking into your sample and I modified it, so now it works as you want. Basically I handled the XamDataChart’s Loaded event and programmatically changed the Legend’s ContentPresenter’s Content from StackPanel to WrapPanel. Please let me know if this helps you or you need further clarifications on this matter.
Thanks a lot! all good now.
Cheers,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Hey Stefan,
I'm trying to give the user an option to have the Legend on the graph display it's items vertically or dock the legend below the chart with it's items displayed horizontally. Unfortunately when I move the legend items children between a wrappanel and a stackpanel just as in your example I get a nasty 'Child already belongs to a parent' exception.
Is it not at all possible to change the content presenters layout like the original poster talked about? It seems that the default items layout in the legends content presenter is a Stackpanel. What I would like to do is have two templates for displaying these legend items in a Wrappanel and in a Stackpanel. If I can just figure out how to set the legend items display in Xaml I'm sure I can figure out the rest.
I though something like this might work but I think this is just template for each item in the legend and not a template around the items in a legend.
<ContentPresenter x:Name="ContentPresenter"> <!--<ContentPresenter.ContentTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <ContentPresenter Content="{Binding}" ContentTemplate="{Binding Series.LegendItemTemplate}" VerticalAlignment="Center"/> </StackPanel> </DataTemplate> </ContentPresenter.ContentTemplate>--> </ContentPresenter>
I would really appreciate any help I can get.
This feature is not yet implemented, but you can use a workaround. You can inherit the LegendBase class and create your own legend. I attached a sample project showing how to do so.
Hope this helps you.
I need this also, I need to be able to change the item panel from the default stackpanel to something else. Any word on when this will be made available? This is a pretty normal feature.
any response.
is this product idea implemented ? i am running into the same problem , need to wrap items instead of one item per line in vertical orientation.
I can say that the Legend is separate element from the XamDataChart. In order to make the Legend render over the chart you have to add it to the Visual Tree after you add the chart and I can suggest you add the Chart and the Legend in a DockManager or Grid, so you can organize them as you want. In the Feature Browser under xamDataChart / Display – Legends / Legend Docking section there is a sample demonstrating how to place the Legend.