2012-05-07 175 views
5

我使用MahApps.Metro在我的应用中实现Metro UI。WPF中的样式覆盖

我有一个listview和MahApps.Metro正在改变它的风格。 MahApps的listview风格是here

的风格装载:

<Window.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedSingleRowTabControl.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" /> 
      <ResourceDictionary Source="pack://application:,,,/FineRSS;component/Resources/Icons.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Window.Resources> 

我需要跟踪所选listviewitems的,所以我用另一个方法:

<ListView.ItemContainerStyle> 
       <Style TargetType="{x:Type ListViewItem}"> 
        <Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/> 
       </Style> 
</ListView.ItemContainerStyle> 

但MahApps.Metro的风格改写为ListView控件的默认。

我能做些什么来保持样式和IsSelected绑定?

回答

10

我不是正面的我遵循你正在做的事情,但它会有意义使你的StyleBasedOn默认的加载?

喜欢的东西

<ListView.ItemContainerStyle> 
    <Style TargetType="{x:Type ListViewItem}" 
      BasedOn="{StaticResource {x:Type ListViewItem}}"> 
     <Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/> 
    </Style> 
</ListView.ItemContainerStyle> 
+0

虽然VS不喜欢行支持算法FMP = “{StaticResource的{X:类型的ListViewItem}}” 这似乎是工作。谢谢。 – ieaglle

+0

我有同样的问题。仍然习惯于使用XAML。 – cubski