WPF unexpected control unload?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

If you want to keep state across itemdetails you should put the state in something else than the UserControls that are used to display itemdetails.

Up vote 1 down vote favorite share g+ share fb share tw.

Im developing a WPF application using MVVM. Inside a Window, I have a control that inherits from UserControl, lets call it DetailView. DetailView is binded to a property in the VM (CurrentDetail) that can be diferent types, UserDetail, AccountDetail, CalendarDetail, etc. All inherit from the same class I have a "ThumbnailBar" in which I can navigate between different detail instances that have been already opened, imagine AccountDetail1, AccountDetail2, etc. This navigation is handled updating CurrentDetail in the VM and with the OnPropertyChanged event The problem comes when I switch from one type (AccontDetail3 for example) to another different (UserDetail6).

I have noticed it calls the "Unloaded" event of the control i'm leaving and the control im going to is Initialized, both things don't happen when I navigate through instance of the same type This cause me some problems, like in calendar where I have a telerik RadScheduler that won't keep the date I had navogated to and reload with the today date. I know and I have already tested, I could save the variable SelectecTimeSlot and keep reloading it, but that would be just a patch Thanks in advance, and tell me if you need more specific info EDIT - some code: Here is MainView. Xaml where I call CurrentDetailsWorkSpace And here is CalendarView (one of the views thas unloads) and yes Im using DataTemplates Here the extract of AccountView where im using DataTemplates too So using different DataTemplates for every type forces the unloading, that makes sense, any idea to solve that?

EDIT - I have DataTemplates. Xaml with DataTemplate for each type in a ResourceDictionary, example: Thanks! Related post I've already read: In wpf, is there a way to execute code before the control is unloaded...? like maybe an unloading event?

http://stackoverflow.com/questions/2080764/wpf-tabcontrol-how-to-preserve-control-state-within-tab-items-mvvm-pattern wpf wpf-controls wpf-usercontrols unload link|improve this question edited Mar 16 '11 at 11:05 asked Mar 15 '11 at 10:59Juan558 100% accept rate.

– Jon Mar 15 '11 at 11:01 If you're using MVVM, and binding the scheduler's date to your ViewModel using two-way binding, then I would expect it to maintain that value even if the control is unloaded and re-created. Are you using MVVM? – Joe White Mar 15 '11 at 11:44 Yes I'm using MVVM, sorry for not saying it.

I could use this approach the thing is don't want the control to unload, is that possible? – Juan Mar 15 '11 at 11:52 We would need to know more about how you're loading the detail view (the one that's getting unloaded when you switch types). Probably you're using DataTemplates with DataType, and if you really don't want to unload the controls, you would need to do something different.

But hard to tell without seeing your code. – Joe White Mar 15 '11 at 19:25 Im using DataTemplates, that's right. I have edit the post and put some code.

Any solution? Thanks – Juan Mar 15 '117 at 7:48.

If you want to keep state across itemdetails you should put the state in something else than the UserControls that are used to display itemdetails. It is quite normal that the usercontrol (and thus its state) is unloaded when a different type and corresponding usercontrol is loaded. So the patch you are suggesting is more or less a correct solution.

Thanks for the answer. So it's normal behaviour to unload only when they change the type (but inherit from the same subclass that inherits from UserControl), loading a different control(instance) with same type doesn't unload...? – Juan Mar 15 '11 at 11:45 I do not know the implementation but it seems reasonable to me to not re-create the same control again when all that will change is the content bound to the control. – Erno Mar 15 '11 at 14:01 Any help now with the new info?

Thanks – Juan Mar 16 '11 at 15:33 Again, when the date you selected needs to be kept across items do not put it in the DataTemplates of the items. – Erno Mar 16 '11 at 20:32.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions