为什么不显示 metro 标签项的关闭按钮?

Why not show close button of metro tab item?

我正在尝试以编程方式添加 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 Header 字体大小正常但 CloseButtonEnabled 不是 working.Why 请让我 known.Thanks.

您为自己的样式使用了错误的基本样式 (MetroTabItem)。你必须从 keyless 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>

希望对您有所帮助。