我正在尝试通过编程方式添加MetroTabItem
。
MainWindow.xaml.cs
private void AddTabItem(UserControl control,string Header)
{
MetroTabItem mahtab = new MetroTabItem();
mahtab.Content = control;
mahtab.DataContext = control;
mahtab.Header = Header;
mahtab.CloseButtonEnabled = true;
mahtab.Style = (Style)FindResource("TabItem");
mahtab.IsSelected = true;
maintab.Items.Add(mahtab);
}
MainWindow.xaml
<Style x:Key="TabItem" BasedOn="{StaticResource MetroTabItem}" TargetType="{x:Type Controls:MetroTabItem}">
<Setter Property="CloseButtonEnabled" Value="True"></Setter>
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="20"></Setter>
</Style>
当我这样添加时,TabItem
标题字体大小正常,但CloseButtonEnabled
无效。为什么请让我知道。谢谢。
答案 0 :(得分:1)
您使用了错误的基本样式(MetroTabItem
)作为您自己的样式。您必须继承无密钥MetroTabItem
样式,如下所示:
<Style x:Key="TabItem" BasedOn="{StaticResource {x:Type Controls:MetroTabItem}}" TargetType="{x:Type Controls:MetroTabItem}">
<Setter Property="CloseButtonEnabled" Value="True"></Setter>
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="20"></Setter>
</Style>
希望这有帮助。