WPF 中的样式覆盖



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

我有一个列表视图,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>

我需要跟踪选定的列表视图项,所以我正在使用下一个方法:

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

但是MahApps.Metro的样式被覆盖为ListView的默认值。

如何保持样式和 IsSelected 绑定?

我不肯定我遵循您要做的事情,但是将您的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> 

相关内容

  • 没有找到相关文章

最新更新