开发者

WPF TabControl rebinding every time

开发者 https://www.devze.com 2023-01-21 07:54 出处:网络
I am data templating a tab control. Each time I select a tab, the binding of the contents get applied. So for eg, if开发者_如何学Go I have a tree view expanded in tab1 and going to tab2 and coming bac

I am data templating a tab control. Each time I select a tab, the binding of the contents get applied. So for eg, if开发者_如何学Go 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号