WPF:列表框DisplayMember

no9*_*no9 2 c# wpf listbox listboxitem

我使用Listbox来呈现一个表.它使用DisplayMemberPath来显示项目.

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

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

日Thnx

dec*_*one 9

用一个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>
Run Code Online (Sandbox Code Playgroud)