Style Styles in WPF

I use MahApps.Metro to reach the Metro interface in my application.

I have a listview and MahApps.Metro is changing the style for it. MahApps styles for listview here .

Loading styles:

<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>

I need to track selected listviewitems, so I use the following approach:

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

But the MahApps.Metro style is overwritten by default in the ListView.

What can I do to preserve both styles and bind IsSelected?

+5
source share
1 answer

I'm not sure that I am following what you are trying to do, but does it make sense to make your Stylebe BasedOnloaded by default?

Sort of

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

All Articles