样式覆盖WPF

iea*_*lle 6 wpf xaml styles

我正在使用MahApps.Metro在我的应用程序中实现Metro UI.

我有一个listview和MahApps.Metro正在改变它的风格.列表视图的MahApps样式就在这里.

加载款式:

<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>
Run Code Online (Sandbox Code Playgroud)

我需要跟踪选定的listviewitems,所以我正在使用下一个方法:

<ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/>
                </Style>
</ListView.ItemContainerStyle>
Run Code Online (Sandbox Code Playgroud)

但MahApps.Metro的风格被覆盖为ListView的默认风格.

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

Tim*_*Tim 11

我不是肯定的,我遵循你想要做的事情,但是让你Style成为BasedOn默认的是有意义的吗?

就像是

<ListView.ItemContainerStyle> 
    <Style TargetType="{x:Type ListViewItem}" 
           BasedOn="{StaticResource {x:Type ListViewItem}}"> 
        <Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/> 
    </Style> 
</ListView.ItemContainerStyle> 
Run Code Online (Sandbox Code Playgroud)