如何创建每个 TabItem 具有多个标题的 WPF TabControl?
描述:
目前我正在创建一个 WPF 应用程序,其中主要内容应在 TabControl 中呈现。
TabControl 存在:
- TabItem,包含具有多个视图的外部控件,其中每个视图应作为 TabControl 上的标题可见;
- 多个 TabItem 包含我们自己的内容,每个 TabItem 都有自己的标题。
WPF 控件的样式不是问题,但这种情况需要控件本身的一些特殊行为。问题是该控件应该为每个 TabItem 呈现多个标题。
问题:
- 针对这种情况使用的最佳控件是什么?
- 如果使用TabControl,应该做哪些修改?
提前致谢。
更新 #1
为了响应 vortex 此类控件的原型(如您所见,外部控件是 Microsoft Office InfoPath FormControl):
<TabControl x:Name="FormViewsTabControl">
<TabItem>
<TabItem.Headers>
<TabItemHeader Text="View A" />
<TabItemHeader Text="View B" />
</TabItem.Headers>
<TabItem.Content>
<winforms:WindowsFormsHost x:Name="InfoPathFormsHost">
<infopath:FormControl x:Name="InfoPathFormControl" />
</winforms:WindowsFormsHost>
</TabItem.Content>
</TabItem>
<TabItem Header="Letter">
<local:CustomView />
</TabItem>
</TabControl>
Description:
Currently I'm in the process of creating a WPF application where the main content should be presented in a TabControl.
The TabControl exists of:
- A TabItem that contains an external control which has multiple views, whereby each view should be visible as Header on the TabControl;
- Multiple TabItems with our own content, each one with it's own header.
Styling of WPF controls is not the problem, but this case requires some special behaviour of the control itself. The problem is that the control should render multiple Headers per TabItem.
Questions:
- What is the best control to use for such a scenario?
- If using TabControl, what modifications should be made?
Thanks in advance.
Update #1
In response to vortex a prototype of such a control (as you can see, the external control is the Microsoft Office InfoPath FormControl):
<TabControl x:Name="FormViewsTabControl">
<TabItem>
<TabItem.Headers>
<TabItemHeader Text="View A" />
<TabItemHeader Text="View B" />
</TabItem.Headers>
<TabItem.Content>
<winforms:WindowsFormsHost x:Name="InfoPathFormsHost">
<infopath:FormControl x:Name="InfoPathFormControl" />
</winforms:WindowsFormsHost>
</TabItem.Content>
</TabItem>
<TabItem Header="Letter">
<local:CustomView />
</TabItem>
</TabControl>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我理解正确,那么您希望根据您在外部控件中选择的视图来更改 TabItems 标题。如果是这种情况,那么您应该尝试使用保存实际标头值的属性来扩展外部控件,然后将其绑定到 TabItmes 标头。
If i understand it correctly then you would like to change the TabItems header depending on which view you select in your external control. If that's the case then you should try to expand your external control with a property which holds the actual header value and then bind this to the TabItmes header.
您可以拥有它,以便 TabItem.Header 包含一个 Panel 元素,该元素可以包含多个子元素。例子:
You can have it so that the TabItem.Header contains a Panel element, which can contain multiple child elements. Example:
我们使用了以下链接
[http://zamjad.wordpress.com/2011/09/21/using-contenttemplateselector/]
当我们遇到此类问题时,
We used the following link
[http://zamjad.wordpress.com/2011/09/21/using-contenttemplateselector/]
when we faced with these type of issue