2016-11-30 64 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

相關問題