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
Hello Henri,
Thank you for your post. I have been looking into your requirement and following the sample application provided in the referred forum thread I have managed to achieve the desired functionality.
Maybe you have missed to apply the ContentTemplate for the legend.
I am attaching a descriptive sample application(DataChartLegendItemWrapping.zip).
Please let me know, if you need any further assistance on this matter.
Hi and thanks for your quick answer!
I tried your solution but still get the same exception after DataChart_Loaded is executed: "Specified element is already the logical child of another element. Disconnect it first."
I updated Infragistics to version 13.2 but it didn't help. Error occurs on both debug and release version of the sample.
edit: here is the stack trace
Hi,
Thank you for your reply. I have been looking into it and could you please explain me how exactly this exception appears ?
Looking forward to hearing from you.
Hi!
The exception is thrown right after DataChart_Loaded handler is run. I can step through the handler in debugger and every line runs without errors. After handler is done and program execution continues, the exception is thrown.
edit: From my previous post's stack trace we can see it is thrown from Infragistics.Controls.Charts.Legend.AddChildInOrder(UIElement legendItem, Series series)
...at System.Collections.ObjectModel.Collection`1.Insert(Int32 index, T item)at Infragistics.Controls.Charts.Legend.AddChildInOrder(UIElement legendItem, Series series)at Infragistics.Controls.Charts.Series.AssertLegendItems(LegendBase oldLegend, LegendBase newLegend)at Infragistics.Controls.Charts.Series.OnSeriesAttached()at Infragistics.Controls.Charts.SeriesView.Series_Loaded(Object sender, RoutedEventArgs e)at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)...
Hello,
Thank you for your feedback. This exception occurs because of the used custom approach.
After working on this and doing some research, this functionality has been determined to be a new product idea. You can suggest new product ideas for future versions (or vote for existing ones) at <http://ideas.infragistics.com>.
There are many benefits to submitting an product idea:
- Direct communication with our product management team regarding your product idea.
- Notifications whenever new information regarding your idea becomes available.
- Ability to vote on your favorite product ideas to let us know which ones are the most important to you. You will have ten votes for this and can change which ideas you are voting for at any time.
- Allow you to shape the future of our products by requesting new controls and products altogether.
- You and other developers can discuss existing product ideas with members of our Product Management team.
Steps to create your idea:
The Product Idea site puts you in the driver’s seat and allows you to track the progress of your ideas at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Thank you for contacting Infragistics.
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?