设置 WPF TabControl 为每个选项卡显示相同的内容 [英] Set WPF TabControl to show the same Content for every tab
问题描述
我想使用 TabControl,其中每个选项卡都显示相同的视图,只是参数不同.因此,我不想为每个选项卡创建一个新的内容控件,而是为所有选项卡重用相同的控件(将它的某些属性绑定到 TabControl
的 SelectedItem
属性)
I'd like to use a TabControl where each tab shows the same view just with different parameters. Therefore I do not want to create a new content control for each tab but reuse the same control for all tabs (binding some properties of it to the SelectedItem
property of the TabControl
)
我尝试将包含的控件作为资源并将选项卡项的 Content
属性设置为它,但这导致了异常,因为相同的元素不能作为内容出现在不同的父项中.
I tried to my contained control as resource and set the Content
property of the tab items to it, but this resulted in an exception, because the same element cannot appear as content in to different parents.
有什么想法吗?
推荐答案
<TabControl>
<TabControl.ContentTemplate>
<DataTemplate>
your view
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
这篇关于设置 WPF TabControl 为每个选项卡显示相同的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!