我如何在wpf中为组合框的选定项目编写项目模板

问题描述

|| 我为wpf组合框创建了一个项模板,以在组合框项中显示和对象的多个属性。
<ComboBox x:Name=\"cmbType\" Grid.Column=\"2\" Grid.Row=\"0\" Grid.ColumnSpan=\"1\"
        SelectedItem=\"{Binding Current.Type,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}\" IsEditable=\"False\"
        ItemsSource=\"{Binding Types,Mode=OneWay}\" DropDownClosed=\"cmbIncidentType_DropDownClosed\" TabIndex=\"601\">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width=\"10\" />
                    <ColumnDefinition Width=\"4\" />
                    <ColumnDefinition Width=\"*\" />

                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column=\"0\" Text=\"{Binding ID}\" />
                <TextBlock Grid.Column=\"2\" Text=\"{Binding Name}\" />
            </Grid>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>
到目前为止,它的完美之处在于它在组合框项目中同时显示了ID和类型的名称,但是现在我想要当我选择一个项目时,它应该仅在组合框的文本区域中显示所选项目的名称,而不是同时显示ID和名称。 谁能帮忙吗?     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)