WPF ListView中的多行文字 [英] Multiline text in WPF ListView

查看:56
本文介绍了WPF ListView中的多行文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF ListView,需要填充一些文本数据.我希望此文本在每个ListView行中多行显示.

I have a WPF ListView that I need to populate with some text data. I would like this text to be on multiple lines in each ListView row.

示例:

Person 1 | Address
Age:     | Address2

Person 2 | Address
Age:     | Address2

等等.

我也想设置文本格式,出于我的目的,所有这些都放在一个单列的ListView中.

I would like to also format the text, and for my purposes this would all be in a one-column ListView.

如果不可能使用多行,是否有更好的控件来显示绑定数据的垂直列表,该列表也允许选择?

If multiline is not possible, is there a better control for displaying a vertical list of binded data that allows for selection as well?

推荐答案

您可以设置ListBox的ItemTemplate来实现类似的目的

You can set the ListBox's ItemTemplate to achieve something like that

<ListView ItemsSource="{Binding People}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <StackPanel>
                    <TextBlock Text="{Binding Name}" />
                    <TextBlock Text="{Binding Age, StringFormat='Age: {0}'}" />
                </StackPanel>
                <StackPanel Grid.Column="1">
                    <TextBlock Text="{Binding Address1}" />
                    <TextBlock Text="{Binding Address2}" />
                </StackPanel>
            </Grid>                    
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

这篇关于WPF ListView中的多行文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆