6

我正在使用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>

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

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

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

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

4

1 回答 1

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> 
于 2012-05-07T21:32:09.110 回答