WPF DataGridComboBoxColumn [英] WPF DataGridComboBoxColumn

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

问题描述

您好我正在使用WPF DataGrid,我正在尝试让ComboBox列工作。

Hello I'm using the WPF DataGrid and I'm trying to get the ComboBox Column to work.

<tk:DataGridComboBoxColumn Header="GroupLevel"
                           DisplayMemberPath="Type"
                           SelectedItemBinding="{Binding Path=GroupLevel}"
                           >
    <tk:DataGridComboBoxColumn.EditingElementStyle>
        <Style TargetType="ComboBox">
            <Setter Property="ItemsSource" Value="{Binding Path=GroupLevel.Group.GroupLevels}" />
        </Style>
    </tk:DataGridComboBoxColumn.EditingElementStyle>

</tk:DataGridComboBoxColumn>

当我看着网格时,列是空白的,就像它不使用显示成员路径。但是一旦我点击列中的组合框显示,并显示我的ItemsSource中的所有项目,并选择一个适当的,所以我知道绑定都工作正常,甚至DisplayMemberPath。

When I look at the grid, the column is blank, like its not using the display member path. But once I click in the column the combobox shows up and shows all the items in my ItemsSource and selects the proper one, so I know the bindings are all working correctly, even the DisplayMemberPath. Its just when I'm not editing the cell that it shows up blank.

我错过了一个地方吗?

感谢,
Raul

Thanks, Raul

推荐答案

im可以肯定这是因为当你不处于编辑模式您的列没有项目源,并且ComboBox不能有没有项目源的选定项目。一旦你去编辑模式你的列获得其项目源,一切都很酷。你可以通过指定一个项目来源来解决这个问题: -

im pretty sure that this is because when you are not in edit mode your Column does not have an items source and a ComboBox cant have a selected item without an items source. as soon as you go to edit mode your column gets its items source and everything is cool. you can fix this by specifying an items source like so :-

<tk:DataGridComboBoxColumn.ElementStyle>
    <Style TargetType="ComboBox">
        <Setter Property="ItemsSource" Value="{Binding Path=GroupLevel.Group.GroupLevels}" />
    </Style>
</tk:DataGridComboBoxColumn.ElementStyle>

那么你的编辑元素和你的(非编辑)元素都有相同的ItemsSource

then both your editing element and your (non-editing)element has the same ItemsSource

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

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