I'm using MahApps.Metro to achieve Metro UI in my app.
I have a listview and MahApps.Metro is changing style for it. MahApps styles for listview are here.
Loading of 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 keep track of selected listviewitems so I'm using the next approach:
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/>
</Style>
</ListView.ItemContainerStyle>
But MahApps.Metro's style is overwritten to ListView's default.
What can I do to keep either styles and IsSelected binding?
WPF - Styles - The .NET framework provides several strategies to personalize and customize the appearance of an application. ... Multiple properties can be added into a single style. Styles are used to give a uniform look or appearance to a set of controls.
In this article I will introduce you into the concept of WPF Styles and Triggers. WPF Styles consist of Setters and Triggers that are supposed to change the Style and Behavior of a Control. From a technical point of view the purpose of Styles is to set Dependency Properties on a Control.
Overriding control templates in WPF requires you to completely replace the template. You may have wanted to change just the one aspect of the template but the result of that is Expression dumping a copy of the rest of the template so that it can be overridden.
The scope of styles are similar to any other resources. The resource lookup process first looks at local styles and if not found, it traverses to the parent element in the logical tree and so on. In the end, the resource lookup process looks for styles in the application and themes. The Style element in XAML represents a style.
I'm not positive I follow what you're trying to do, but would it make sense to make your Style
be BasedOn
the default one that is loaded?
Something like
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}"
BasedOn="{StaticResource {x:Type ListViewItem}}">
<Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/>
</Style>
</ListView.ItemContainerStyle>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With