Reputation:
I am trying to add MetroTabItem
by programmatically.
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>
When i adding like this,TabItem
Header font size is working but CloseButtonEnabled
is not working.Why please let me known.Thanks.
Upvotes: 0
Views: 746
Reputation: 14611
You used the wrong base Style (MetroTabItem
) for your own Style. You must inherited from the keyless MetroTabItem
Style like this:
<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>
Hope this helps.
Upvotes: 2