WPF overriding ListViewItem style when use Material Design In XAML Toolkit

Viewed 6953

I installed Material Design In XAML Toolkit to my project. I have ListView which contains within itself GridView (with GridViewColumns) and i want to override styles for each row in this table. But in each case i lose styles from Material Design In XAML Toolkit.

I tried do several things:

1) Override existing styles based on target type:

<ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem" BasedOn="{StaticResource {x:Type ListViewItem}}">
        <Setter Property="Background" Value="Green" />
    </Style>
</ListView.ItemContainerStyle>

I got overriding styles, but in this case i lose type recognition in GridView (Columns contains correct headers, but values contains call result ToString() method my model)

2) I used concrete style from Material Design In XAML Toolkit - MaterialDesignGridViewItem:

<ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem" BasedOn="{StaticResource MaterialDesignGridViewItem">
        <Setter Property="Background" Value="Green" />
    </Style>
</ListView.ItemContainerStyle>

In this case i got work solution (it would seem), but when i do adding triggers instead , i lose material styles (got only color, without animations).

3) In other cases i lose all material styles and go back to wpf default styles.

Hope on our help.

3 Answers

The same works for other items. This helped me with TreeViewItem's that used to be in the style of MaterialDesign, but were also overwritten until I added the BasedOn property.

<TreeView.ItemContainerStyle>
    <Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource MaterialDesignTreeViewItem}">
        <EventSetter Event="TreeViewItem.DragOver"  Handler="treeView_DragOver"/>
        <EventSetter Event="TreeViewItem.Drop" Handler="treeView_Drop"/>
        <EventSetter Event="TreeViewItem.MouseMove" Handler="treeView_MouseMove"/>
        <EventSetter Event="TreeViewItem.MouseLeftButtonDown" Handler="treeView_MouseDown"/>
        <EventSetter Event="TreeViewItem.MouseRightButtonDown" Handler="treeView_MouseRightDown"/>
    </Style>
</TreeView.ItemContainerStyle>

Please note a "}" is missing after "MaterialDesignListBoxItem", so that:

<Style TargetType="ListViewItem" BasedOn="{StaticResource MaterialDesignListBoxItem}">
Related