问题
I'm trying to override the ListViewItem style using this code:
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource MaterialDesignListViewItem}">
<EventSetter Event="PreviewMouseLeftButtonDown"
Handler="ListViewItem_PreviewMouseLeftButtonDown" />
</Style>
</ListView.ItemContainerStyle>
unfortunately seems that MaterialDesignListViewItem
isn't included in the MaterialDesignInXaml
so I got the StaticResource
underlined for not found.
My goal is change the color of selection when the mouse is over an item.
Thanks for the attention.
回答1:
So there are a few things going on here.
In MDIX there are two styles that are used for ListViews. The grouped style, MaterialDesignGridViewItem
and the normal MaterialDesignListBoxItem
. To override either of these styles you will need to manually bring in the appropriate resource dictionary (MaterialDesignTheme.ListView.xaml
and MaterialDesignTheme.ListBox.xaml
respectively).
I think you are looking for something like this:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem" BasedOn="{StaticResource MaterialDesignListBoxItem}">
<Style.Resources>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ListBox.xaml" />
</Style.Resources>
<EventSetter Event="PreviewMouseLeftButtonDown"
Handler="ListViewItem_PreviewMouseLeftButtonDown" />
</Style>
</ListView.ItemContainerStyle>
来源:https://stackoverflow.com/questions/48035365/how-to-override-listviewitem-style