\"+开发者_运维问答object.description) I\'m pretty sure I can do this by creating a dynamic da" />
开发者

Compound DisplayMemberPath for a combobox

开发者 https://www.devze.com 2023-04-10 20:35 出处:网络
I need to create a DisplayMemberPath that is a compound of a few properties (ie object.category.Name+\" -> \"+开发者_运维问答object.description) I\'m pretty sure I can do this by creating a dynamic da

I need to create a DisplayMemberPath that is a compound of a few properties (ie object.category.Name+" -> "+开发者_运维问答object.description) I'm pretty sure I can do this by creating a dynamic data type that encapsulates the object and also adds a new property called displayField that is what I need but I'm wondering if there is a more proper way to do this that does not involve creating a new object. Any ideas?


DisplayMemberPath is just a "shortcut" for when you don't need a complex template for items. If you need more control, use ItemTemplate instead:

<ComboBox ItemsSource="{Binding Items}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock>
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}{0} -> {1}">
                        <Binding Path="Category.Name" />
                        <Binding Path="Description" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>
0

精彩评论

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