Jump to content
Software FX Community

Binding stops working when UserControl containing a chart is moved between containers


thubble
 Share

Recommended Posts

There seems to be a bug when using binding on the chart's ItemsSource property. Steps to reproduce:

1. Create a UserControl that contains a chart. Bind the ItemsSource property of the chart to an ObservableCollection property in the code-behind of the UserControl.

2. Have a button on the UserControl that clears the ObservableCollection and adds new data (i.e. to change the data in the chart)

3. Everything works fine at this point - the button refreshes the chart as it should. Now, in some sort of event (e.g. on a Button Click event on the original window), detach the UserControl from its original container (grid, panel, etc) and attach it to a ContentPresenter in another window, then display the other window. The current data on the chart will display fine, but clicking the button no longer refreshes the chart.

 I'm pretty sure this is a ChartFX issue, since if I have a combo box on the UserControl which uses exactly the same binding, there is no problem. I have a test app that reproduces this issue, please let me know if you want me to send it.

Thank you.

Link to comment
Share on other sites

When a chart is Unloaded we clean up a lot of things to avoid leaks, one of those things was disconnecting from data change events and we were not properly connecting them back when the chart was reloaded (because the data is not reread). We have fixed this on any build marked 3457 or greater.

If moving a chart from containers is a common occurrence in your app you might also want to consider turning on a flag called "KeepVisualsOnUnload" using the Chart.AdvancedSettings property. When this flag is on we will not do the cleanup as this flag is a hint that the chart will be reloaded shortly so it might improve your performance. Please note that in builds previous to 3457 we were disconnecting from collection events even if this flag was on so you still need to download an update even if you decide to use this flag. Also note that if you use this flag you must turn it off on the chart's parent Unloaded event to avoid memory leaks.

One more thing, there is still an issue when the chart is Unloaded/Reloaded where binding will stop on a per-object level, i.e. when you pass a collection of objects that implement INotifyPropertyChange. We are working on a fix for this issue.

Regards,

JuanC

Link to comment
Share on other sites

Please make sure you use KeepVisualsOnUnload with caution as it might cause memory leaks, our recommendation would be to use it only if you can perceive/measure a performance difference.

Note that build 3460 should have fixed the binding issue even if you do not use this flag.

Regards,

JuanC

Link to comment
Share on other sites

Please note that hotfixes do not go through the same level of testing as service packs. Because of this you should only download a hotfix if you are experiencing a specific issue or need a new feature implemented in it.

Also note that we use an ActiveX control that needs acces to modify your files so you must run IE as an administrator if you have UAC enabled in Vista or Windows 7.

You can download our most recent hotfix here.

Regards,

JuanC

Link to comment
Share on other sites

Is there a way to turn off KeepVisualsOnUnload when I really want to dispose of the chart?

In my case, I may have multiple charts in multiple tabs that I want to switch back and forth between, but I also want to be able to close the tabs when I'm done with them, and then really dispose of the chart's resources from that tab. How can I do this?

Link to comment
Share on other sites

This is a simplified sample where we turn on the flag in the window/page constructor and turn it off when the window/page is unloaded

<TabControl>   <TabItem Header="Chart">   <cfx:Chart x:Name="chart1"/>   </TabItem>   <TabItem Header="Other">   <cfx:Chart x:Name="chart2" Gallery="Pie"/> </TabItem></TabControl>public TabPage (){   InitializeComponent();   chart1.AdvancedSettings |= ChartSettings.KeepVisualsOnUnload;   chart2.AdvancedSettings |= ChartSettings.KeepVisualsOnUnload;   this.Unloaded += new RoutedEventHandler(OnPageUnloaded);}

void OnPageUnloaded (object sender, RoutedEventArgs e){   chart1.AdvancedSettings &= ~ChartSettings.KeepVisualsOnUnload;   chart2.AdvancedSettings &= ~ChartSettings.KeepVisualsOnUnload;}

In your case, you would want to turn off the flag when the tab is being closed removed for good, I would recommend you attach to the Chart's Unloaded event and add a breakpoint there as well as the line of code where you turn off the flag. If turning off the flag occurs before the last Unloaded event it means resources will be disposed properly.

Regards,

JuanC

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...