开发者

How do I Style ListView Items?

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 DisplayMemberB开发者_运维技巧inding="{Binding UpdateData}" />
        </GridView>
    </ListView.View>
</ListView>


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" ...>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜