Is it possible to create wrapping horizontal legend?

Not Answered This post has 0 verified answers | 10 Replies | 2 Followers Thread's RSS feed.

Tg
Points 360
Replied On: Wed, Feb 12 2014 3:54 AM Reply

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

  • Post Points: 20

All Replies

[Infragistics] Yanko
Points 35,314
Infragistics Employee
Replied On: Wed, Feb 12 2014 9:11 AM Reply

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.

 

Best regards,
Yanko
Developer Support Engineer
Infragistics, Inc.

  • Post Points: 20
Tg
Points 360
Replied On: Thu, Feb 13 2014 2:20 AM Reply

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.

Best regards, Henri

edit: here is the stack trace

  • Post Points: 20
[Infragistics] Yanko
Points 35,314
Infragistics Employee
Replied On: Fri, Feb 14 2014 6:45 AM Reply

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.

Best regards,
Yanko
Developer Support Engineer
Infragistics, Inc.

  • Post Points: 20
Tg
Points 360
Replied On: Fri, Feb 14 2014 7:12 AM Reply

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.

Best regards, Henri

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)
...

  • Post Points: 20
[Infragistics] Yanko
Points 35,314
Infragistics Employee
Replied On: Fri, Feb 14 2014 10:30 AM Reply

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:

               

  1. Log into the Infragistics Product Idea site at http://ideas.infragistics.com (creating a new login if needed).
  2. Navigate to the product / platform channel of your choice (e.g. WPF, Windows Forms, ASP.NET, HTML5 / Ignite UI, iOS / NucliOS, etc.)
  3. Add your product idea and be sure to be specific and provide as much detail as possible. Explain the context in which a feature would be used, why it is needed, why it can’t be accomplished today, and who would benefit from it. You can even add screenshots to build a stronger case. Remember that for your suggestion to be successful, you need other members of the community to vote for it. Be convincing!

 

 

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.

Best regards,
Yanko
Developer Support Engineer
Infragistics, Inc.

  • Post Points: 20
Tg
Points 360
Replied On: Mon, Feb 17 2014 6:55 AM Reply

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.

Best regards, Henri

  • Post Points: 20
[Infragistics] Yanko
Points 35,314
Infragistics Employee
Replied On: Mon, Feb 17 2014 10:53 AM Reply

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.

Best regards,
Yanko
Developer Support Engineer
Infragistics, Inc.

  • Post Points: 20
Tg
Points 360
Replied On: Fri, Feb 21 2014 3:32 AM Reply

Hi!

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?

Best regards, Henri

  • Post Points: 35
[Infragistics] Yanko
Points 35,314
Infragistics Employee
Replied On: Wed, Feb 26 2014 1:52 AM Reply

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.

Best regards,
Yanko
Developer Support Engineer
Infragistics, Inc.

  • Post Points: 5
[Infragistics] Yanko
Points 35,314
Infragistics Employee
Replied On: Tue, Mar 4 2014 1:36 AM Reply

Hello,

 

I am just checking if you require any further assistance on the matter.

Best regards,
Yanko
Developer Support Engineer
Infragistics, Inc.

  • Post Points: 5
Page 1 of 1 (11 items) | RSS