WPF 选项卡项中的滚动条问题
我有一个选项卡控件,它有一整套可关闭的选项卡项目,每个选项卡项目都有一个带有可滚动部分的视图(每个视图都是相同的不同实例),我遇到的问题是,如果您在一个选项卡上滚动它会级联到所有其他选项卡,我在想是否有人可以告诉我如何阻止这种情况发生?
谢谢大家:)
I have a Tab Control that has a whole set of close able tab items, each tab item has View with a that has a scroll able section(each view is the same not same instance), the issue that I am having is that if you scroll on one tab its cascades to all the other tabs, I was wandering if someone can tell me how I can stop this from happening?
Thanks All :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的
TabControl
指定了ContentTemplate
,这是默认行为。TabControls 使用虚拟化,因此当您切换选项卡时它们将重新使用模板,而不是每次都创建一个新选项卡。这意味着无论您位于哪个选项卡上,都会使用相同的
ScrollViewer
。您可以通过向ScrollViewer
添加Loaded
事件来证明这一点,您将看到它只被调用一次。解决此问题的一种方法是使用具有
x:Shared="False"
的 DataTemplate,这样它就不会共享模板。我还没有测试过这是否有任何性能问题。请注意,这似乎非常繁琐......例如,我需要将我的
ScrollViewer
放在UserControl
中,否则它将无法工作。我还需要设置TabItem.ContentTemplate
而不是TabControl.ContentTemplate
。This is the default behavior if your
TabControl
specifies aContentTemplate
.TabControls use virtualization, so they will re-use the template when you switch tabs instead of creating a new one each time.This means the same
ScrollViewer
is being used regardless of which tab you are on. You can prove this by adding aLoaded
event to yourScrollViewer
and you'll see it only gets called once.One way around this is to use a DataTemplate that has
x:Shared="False"
, so it won't share the template. I have not tested to see if there are any performance issues with this.Note that this seems to be very fussy... for example I need to put my
ScrollViewer
in aUserControl
or it won't work. I also need to setTabItem.ContentTemplate
instead ofTabControl.ContentTemplate
.