[英]Mahapps TabControl, can't set CloseButtonEnabled = true when using ItemSource ={Binding..}
我正在使用MahApps TabControl。 如果我从xaml添加项目,则可以设置“ CloseButtonEnabled = true”,并且显示“关闭”按钮,当我尝试绑定ItemSource时,不显示关闭按钮。 有什么想法,我该如何解决这个问题?
这是我的示例代码:
<Window.Resources>
<Style BasedOn="{StaticResource MetroTabItem}" TargetType="{x:Type Controls:MetroTabItem}">
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="15"/>
<Setter Property="Foreground" Value="Red"/>
<Setter Property="CloseButtonEnabled" Value="True"/>
</Style>
</Window.Resources>
<Controls:MetroTabControl ItemsSource="{Binding AvailableFiles}" SelectedIndex="{Binding SelectedIndex}" Grid.Row="1" >
<Controls:MetroTabControl.ItemTemplate >
<DataTemplate>
<TextBlock Text="{Binding Title}" />
</DataTemplate>
</Controls:MetroTabControl.ItemTemplate>
</Controls:MetroTabControl>
您可以尝试以下方法:
<Window.Resources>
<Style x:Key="MyCustomTabItem" BasedOn="{StaticResource MetroTabItem}" TargetType="{x:Type Controls:MetroTabItem}">
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="15"/>
<Setter Property="Foreground" Value="Red"/>
<Setter Property="CloseButtonEnabled" Value="True"/>
</Style>
</Window.Resources>
<Controls:MetroTabControl ItemsSource="{Binding AvailableFiles}" ItemContainerStyle="{StaticResource MyCustomTabItem}" SelectedIndex="{Binding SelectedIndex}" Grid.Row="1" >
<Controls:MetroTabControl.ItemTemplate >
<DataTemplate>
<TextBlock Text="{Binding Title}" />
</DataTemplate>
</Controls:MetroTabControl.ItemTemplate>
</Controls:MetroTabControl>
这里的问题是您覆盖MetroTabItem
的完整样式。
如果您只想要其他更改,请执行此操作
<Window.Resources>
<Style BasedOn="{StaticResource {x:Type Controls:MetroTabItem}}" TargetType="{x:Type Controls:MetroTabItem}">
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="15"/>
<Setter Property="Foreground" Value="Red"/>
<Setter Property="CloseButtonEnabled" Value="True"/>
</Style>
</Window.Resources>
所述MetroTabItem
在BasedOn="{StaticResource MetroTabItem}"
是一个样式,不类型。
希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.