Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Style ListView Items?

Tags:

listview

wpf

I have a ListView that is data bound and I want to alter the font properties for each item. I'm not having much luck finding the appropriate properties. The ListView is pretty simple so I don't expect it to be too difficult to change, I'm just not finding what I'm wanting as of yet.

<ListView ItemsSource="{Binding Updates}">
    <ListView.View>
        <GridView>
            <GridViewColumn DisplayMemberBinding="{Binding TimeStamp}" Header="TimeStamp" />
            <GridViewColumn DisplayMemberBinding="{Binding UpdateData}" />
        </GridView>
    </ListView.View>
</ListView>
like image 439
Jeff LaFay Avatar asked Dec 17 '10 20:12

Jeff LaFay


1 Answers

You can set the ItemContainerStyle:

<ListView ItemsSource="{Binding Updates}">
    <ListView.View>
        <GridView>
            <GridViewColumn DisplayMemberBinding="{Binding TimeStamp}" Header="TimeStamp" />
            <GridViewColumn DisplayMemberBinding="{Binding UpdateData}" />
        </GridView>
    </ListView.View>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="FontSize" Value="14" />
            <Setter Property="Foreground" Value="Blue" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="FontStyle" Value="Italic" />
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

Note that it will apply to the items of the ListView, not the ListView itself (e.g. the column headers won't be affected). If you want to apply those properties to the whole ListView, you can set them directly on the ListView:

<ListView ItemsSource="{Binding Updates}"
          Foreground="Blue" FontSize="14" ...>
like image 71
Thomas Levesque Avatar answered Nov 11 '22 01:11

Thomas Levesque