与需要帮助TabControl.ItemTemplate [英] Need help with TabControl.ItemTemplate

查看:136
本文介绍了与需要帮助TabControl.ItemTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置TabItem.Header从几个字段所绑定怎么办,每个绑定显示在不同的大小,都在原来的标题文本的地方;无覆盖标题的默认样式和行为 - 我只需要文字

How do I set the TabItem.Header to bindings taken from few fields, each binding shown in a different size, all in the place of the original header text; without overriding the default style and behavior of the header - I only need the text.

我试图设置它的模板,但随后创建了一个包含内部控制一个矩形,这rectengle没有响应用户点击,也有控制的风格,我希望这个控件是unvisible,只有它的文字应该是可见的。

I tried to set its template but then it creates a rectangle that contains the inner controls, and this rectengle is not responsive for user clicks, and also have the control-style, i want this controls to be unvisible, only its text should be visible.

我试过以下内容:

<TabControl ItemsSource="{Binding}">
    <TabControl.ItemTemplate>
         <DataTemplate>
             <TabItem>
                 <TabItem.Header>
                     <MultiBinding StringFormat="{}{0}-{1}">
                         <Binding Path="Title"/>
                         <Binding Path="Category.Title"/>
                     </MultiBinding>
                 </TabItem.Header>
                 <TabItem.Content>
                     <TextBlock>
                         Here is what is gonna be in the TabItem - not header
                     </TextBlock>
                 </TabItem.Content>
             </TabItem>
         </DataTemplate>
    </TabControl.ItemTemplate>
</TabControl>

但它并不显示任何东西。

But it doesn't show anything.

我也试着给HeaderTemplate中设置一个DataTemplate,但发生的事情是,在DataTemplate中覆盖TabItem的风格,当我点击它并没有去点击选项卡中的文本,另外,未选定的标签看起来很滑稽,我看到的文字浮动的rectengle,而我希望它是透明的。

I've also tried to set the HeaderTemplate to a DataTemplate but what happens is, the DataTemplate overrides the TabItem style and when I click the text it doesn't go to the clicked tab, besides, the unselected tabs look very funny, I see the rectengle of the text floating, while I want it to be transparent.

所以,总结起来,我的问题,我想TabItem.Header.Text设置为一个MultiBinding用的StringFormat。

So, to summarize up my question, I want to set TabItem.Header.Text to a MultiBinding with StringFormat.

任何想法将是真正的AP preciated。
谢谢你。

Any idea would be really appreciated. Thanks.

推荐答案

该TabControl的包含的ContentTemplate属性以及ItemTemplate中,它自ItemsControl继承。它使用的ContentTemplate区分什么是同时的ItemTemplate它定义了页眉模板内容区域显示。此外,从你的ItemSource每个项目将自动被包裹在一个TabItem的;它并不需要在ItemTemplate重新创建,因为这将试图将一个TabItem的页眉里面,你都注意到。

The TabControl contains a ContentTemplate property as well as the ItemTemplate that it inherits from ItemsControl. It uses the ContentTemplate to differentiate what is showing in the Content area while the ItemTemplate which defines the template for the Header. Additionally, each Item from your ItemSource will automatically be wrapped in a TabItem; it doesn't need to be re-created in the ItemTemplate, as that will attempt to place a TabItem inside the Header as you are noticing.

而不是重新创造的ItemTemplate内TabItem的,使用的ItemTemplate来定​​义页眉内容和的ContentTemplate来定​​义您的内容。

Instead of re-creating a TabItem inside the ItemTemplate, use the ItemTemplate to define your Header content, and the ContentTemplate to define your Content.

<TabControl ItemsSource="{Binding}">
	<TabControl.ItemTemplate>
		<DataTemplate>
			<TextBlock>
				<TextBlock.Text>
					<MultiBinding StringFormat="{}{0}--{1}">
						<Binding Path="Title" />
						<Binding Path="Category.Title" />
					</MultiBinding>
				</TextBlock.Text>
			</TextBlock>
		</DataTemplate>
	</TabControl.ItemTemplate>
	<TabControl.ContentTemplate>
		<DataTemplate>
			<TextBlock Text="{Binding MyContent}" />
		</DataTemplate>
	</TabControl.ContentTemplate>
</TabControl>

在你的第一段你提到希望在页眉的边界部分设置不同的大小。如果你想这样做,你将无法使用单一的约束力或MultiBinding设置文本作为上面完成。相反,你可以窝的TextBlocks用不同的格式为每个实现这一目标。

In your first paragraph you mentioned wanting to set different sizes on the bound portions of the Header. If you do want to do that, you won't be able to use a single Binding or MultiBinding to set the Text as is done above. Instead you can nest TextBlocks to achieve this with different formatting for each.

<TabControl.ItemTemplate>
	<DataTemplate>
		<TextBlock>
			<TextBlock Text="{Binding Title}"
					   FontSize="12" />
			<Run Text="--" />
			<TextBlock Text="{Binding Category.Title}"
					   FontSize="10" />
		</TextBlock>
	</DataTemplate>
</TabControl.ItemTemplate>

这篇关于与需要帮助TabControl.ItemTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆