views:

19

answers:

1

Hi,

I am data templating a tab control. Each time I select a tab, the binding of the contents get applied. So for eg, if I have a tree view expanded in tab1 and going to tab2 and coming back has this collapsed. The property binded to ItemsSource is invoked each time I flip the tabs.

learned its all because the visual tree gets recreated again and again as selectd item changes.

Now the qn is, any easy way to fix this. Wil be really helpful.

Thanks, Mani

A: 

One way to go is to have an 'IsExpanded' property for a TreeViewItemViewModel and bind to it. Basically your viewmodel will hold the expanded/collapsed state information in your viewmodel.

NVM
The treeview was just an example. Basically, tab control renders the visual tree everytime you flip back and forth between the tabs.
Mani
Yes, but I dont think that's a very bad idea...
NVM
not at all, as I said, I dont have a tree view. this is a wpf tab control issue. wonder how to fix it...
Mani
What I meant is why don't you like the fact that the visual tree refreshes when you change tabs? For example if you have multiple tabs with the same view, WPF will reuse the view rather than generate a new view for each tab.
NVM
Maybe x:Shared attribute is what you are looking for.
NVM