Hi, I have been trying to create xamDataChart with wrapping horizontal legend where legend items show up on multiple lines instead of default behaviour (one line and horizontal scrollbar). I'm using Infragistics version 13.1.
I found similar questions asked here before, and they suggested replacing StackPanel which contains legend items with WrapPanel on datachart's loaded event like this:
private void DataChart_Loaded(object sender, RoutedEventArgs e) { ContentPresenter cp = Utilities.GetDescendantFromName(_legend, "ContentPresenter") as ContentPresenter; WrapPanel wp = new WrapPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal }; StackPanel sp = cp.Content as StackPanel; 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); wp.Children.Add(cc); }
cp.Content = wp; }
This was marked as verified answer here, but I get InvalidOperationException from it: "Specified element is already the logical child of another element. Disconnect it first." Is there something I'm missing here, or has this solution deprecated somewhere before version 13.1?
I also tried a different approach to my problem. Here I define own legends for each serie like this:
<ig:XamDataChart>
...
<ig:ColumnSeries Legend="{Binding ElementName=TitleLegend1}" ...
<ig:ColumnSeries Legend="{Binding ElementName=TitleLegend2}" ...
<ig:ColumnSeries Legend="{Binding ElementName=TitleLegend3}" ...
</ig:XamDataChart>
<ig:XamDock ig:XamDock.Edge="OutsideBottom" ig:XamDock.HorizontalDockAlignment="Center"> <WrapPanel> <ig:Legend x:Name="TitleLegend1" />
<ig:Legend x:Name="TitleLegend2" />
<ig:Legend x:Name="TitleLegend3" />
</WrapPanel>
</ig:XamDock>
This works fine and I like that I can style and construct the whole legend area and individual legends by myself. Legend items wrap nicely to multiple rows when needed. Problem is that my chart can also have stacked series:
<ig:StackedColumnSeries Legend="{Binding ElementName=TitleLegend4}" ... <ig:StackedColumnSeries.Series> <ig:StackedFragmentSeries /> <ig:StackedFragmentSeries /> <ig:StackedFragmentSeries />
</ig:StackedColumnSeries.Series>
</ig:StackedColumnSeries>
So this stacked serie can have only one legend (TitleLegend4) where it show all fragment series using default legend template (StackPanel and no wrapping). Is it possible to define own legend for each StackedFragmentSeries? It would make this solution to work for my needs.
By the way, does this question form support code formatting like for example StackOverflow? It would make writing and reading questions including code snippets much easier.
Best regards, Henri
Hi!
Did you manage to reproduce the exception, or does the suggested solution still work fine for you? I think I'll try to investigate this problem some more time before submitting a new product idea.
Hi Henri,
Thank you for your reply. I managed to reproduce the exception and it depends on the approach that it is used. This is why Stefan had suggested a new product idea to be submitted in the referred forum thread.
Thank you for understanding.
It's a bit strange that at first the suggested solution worked for you. How did you change your approach when you managed to reproduce the exception? Or did it just start occuring using the exactly same code?
What about my second approach that I described in my first post? Is it possible to define individual legend for StackedFragmentSeries?
Hello Henri,
Thank you for your feedback. I managed to reproduce the exception when I add the XamDataChart with the customized legend in a tab of TabControl. After switching through the tabs and coming back to the tab that holds the XamDataChart, the exception is thrown.
Initially I did not add the XamDataChart as a content to another control and this is why I did not reproduce the issue that Stefan had found. This is why this functionality has been suggested to be a new product idea.
Let me know, if you need any further assistance on this matter.
Hello,
I am just checking if you require any further assistance on the matter.