如何进行Wpf TabItem样式HeaderTemplate绑定?
如何进行Wpf TabItem样式HeaderTemplate绑定?
代码:
<TabControl x:Name="tabCtrlMain" ItemsSource="{Binding Items}" >
<TabControl.Resources>
<Style TargetType="TabItem">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type TabItem}">
<TextBlock Text="{Binding FileName}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
</TabControl>
绑定时此代码不起作用:
<TextBlock Text="{Binding FileName}"/>
How To do Wpf TabItem Style HeaderTemplate Binding?
Code:
<TabControl x:Name="tabCtrlMain" ItemsSource="{Binding Items}" >
<TabControl.Resources>
<Style TargetType="TabItem">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type TabItem}">
<TextBlock Text="{Binding FileName}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
</TabControl>
this code is not working when binding:
<TextBlock Text="{Binding FileName}"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这现在已经非常旧了,但我想我应该为了完整性和历史准确性而投入两分钱:)
我更喜欢使用 ItemContainerStyle 来做同样的事情,只是因为它对我来说感觉更干净一些因为它准确地说明了目的:
此外,如果唯一的目标是将文件名放入选项卡中,那么它可以简单得多:
I know this is awfully old now, but I thought I'd throw my two cents in just for the sake of completeness and historical accuracy :)
I prefer to use the ItemContainerStyle to do the same thing just because it feels a little cleaner to me because it states the purpose exactly:
Also, if the only goal is to get the FileName into the tabs then it can be much simpler:
试试这个相反,
Try this Instead,