thubble Posted June 18, 2009 Report Share Posted June 18, 2009 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. Quote Link to comment Share on other sites More sharing options...
JuanC Posted June 18, 2009 Report Share Posted June 18, 2009 Please send the test app to wpf at softwarefx dot com and we will take a look at it. JuanC Quote Link to comment Share on other sites More sharing options...
thubble Posted June 18, 2009 Author Report Share Posted June 18, 2009 Test app sent - let me know if you need any more information. Thanks again. Quote Link to comment Share on other sites More sharing options...
JuanC Posted June 23, 2009 Report Share Posted June 23, 2009 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 Quote Link to comment Share on other sites More sharing options...
thubble Posted June 23, 2009 Author Report Share Posted June 23, 2009 Tested with build 3460, it now works properly when the KeepVisualsOnUnload property is set. Thanks! Quote Link to comment Share on other sites More sharing options...
JuanC Posted June 26, 2009 Report Share Posted June 26, 2009 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 Quote Link to comment Share on other sites More sharing options...
thubble Posted June 29, 2009 Author Report Share Posted June 29, 2009 It looks like build 3460 does fix the binding issue even without KeepVisualsOnUnload, so I've left it unset. Thanks again! Quote Link to comment Share on other sites More sharing options...
Sharon Posted July 2, 2009 Report Share Posted July 2, 2009 Hi, May I know where can i get build 3460? Thanks a lot. Sharon Quote Link to comment Share on other sites More sharing options...
JuanC Posted July 2, 2009 Report Share Posted July 2, 2009 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 Quote Link to comment Share on other sites More sharing options...
dksimon Posted July 2, 2009 Report Share Posted July 2, 2009 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? Quote Link to comment Share on other sites More sharing options...
JuanC Posted July 3, 2009 Report Share Posted July 3, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.