2016-11-30 65 views
0

我正在使用MahApps TabControl。如果我从xaml添加项目,我可以设置“CloseButtonEnabled = true”,并显示关闭按钮,当我尝试绑定ItemSource时,关闭按钮不会出现。任何想法,我怎么能解决这个问题?Mahapps TabControl,无法设置CloseButtonEnabled = true时使用ItemSource = {Binding ..}

这里是我的示例代码:

<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> 

回答

1

这里的问题是,你重写了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> 

BasedOn="{StaticResource MetroTabItem}"MetroTabItem是一种风格,而不是类型。

希望有帮助!

+0

是的是的!它现在有效!谢谢。 – niks

0

你可以试试下面的办法:

<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> 
+0

谢谢你的回答,但它仍然不起作用。 – niks

相关问题