c# - WPF:列表框显示成员

标签 c# wpf listbox listboxitem

我使用列表框来显示表格。 它使用 DisplayMemberPath 来呈现项目。

如何进行多重绑定(bind)以显示项目?

假设我想显示 ID 和 NAME ...是否有模板示例之类的?

谢谢

最佳答案

使用DataTemplate

示例:

<ListBox>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock>
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}{0}, {1}">
                        <Binding Path="ID" />
                        <Binding Path="Name" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

关于c# - WPF:列表框显示成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4655916/

相关文章:

c# - 使用 Swashbuckle 将文本部分添加到 Swagger

c# - 单元测试Azure Function : Cannot create an instance of TraceWriter,如何模拟?

c# - ReactiveUI、WPF 和验证

c# - 数据上下文绑定(bind)

.net - 在 WPF ListBoxItems 中使用 Storyboard动画进行鼠标悬停和选择

c# - WPF 列表框 SelectionChanged 事件

wpf - ItemContainerGenerator.ContainerFromItem() 返回 null?

c# - 将 C# 方法名称转换为文本

c# - 如何检查对象是矩形还是椭圆

wpf - 为画笔创建 WPF ValueConverter