Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF overriding ListViewItem style when use Material Design In XAML Toolkit

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.

like image 779
as94 Avatar asked Sep 24 '17 21:09

as94


1 Answers

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

Instead of using MaterialDesignGridViewItem, your extended style should be based on MaterialDesignListBoxItem.

like image 87
BrendanBenting Avatar answered Sep 28 '22 22:09

BrendanBenting