WPF TabControl 每次都会重新绑定

发布于 2024-09-28 15:43:36 字数 207 浏览 0 评论 0原文

我正在对选项卡控件进行数据模板化。每次我选择一个选项卡时,都会应用内容的绑定。例如,如果我在 tab1 中展开了一个树视图,然后转到 tab2 并返回,则此视图已折叠。每次翻转选项卡时都会调用绑定到 ItemsSource 的属性。

学到了这一切,因为随着所选项目的更改,视觉树会一次又一次地重新创建。

现在的问题是,有什么简单的方法可以解决这个问题。真的会很有帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦言归人 2024-10-05 15:43:36

一种方法是为 TreeViewItemViewModel 提供“IsExpanded”属性并绑定到它。基本上,您的视图模型将在视图模型中保存展开/折叠的状态信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文