WPFToolkit DataGrid:Combobox列不会立即更新selectedvaluebinding [英] WPFToolkit DataGrid: Combobox column does not update selectedvaluebinding immediately

查看:814
本文介绍了WPFToolkit DataGrid:Combobox列不会立即更新selectedvaluebinding的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是WPF Toolkit DataGrid和DataGridComboBoxColumn。一切都很好,除了当组合框发生选择更改时,selectedvaluebinding源不会立即更新。这只发生在组合框失去焦点时。有没有人遇到这个问题和任何建议的解决方案?

I'm using WPF Toolkit DataGrid and DataGridComboBoxColumn. Everything works well, except that when selection change happens on the combobox, the selectedvaluebinding source is not updated immediately. This happens only when the combobox loses focus. Has anyone run into this issue and any suggestions solutions ?

这是列的xaml:

<toolkit:DataGridComboBoxColumn Header="Column" SelectedValueBinding="{Binding Path=Params.ColumnName, UpdateSourceTrigger=PropertyChanged}"
                DisplayMemberPath="cName"
                SelectedValuePath="cName">
                <toolkit:DataGridComboBoxColumn.ElementStyle>
                    <Style TargetType="ComboBox">
                        <Setter Property="ItemsSource" Value="{Binding Info.Columns}" />
                    </Style>
                </toolkit:DataGridComboBoxColumn.ElementStyle>
                <toolkit:DataGridComboBoxColumn.EditingElementStyle>
                    <Style TargetType="ComboBox">
                        <Setter Property="ItemsSource" Value="{Binding Info.Columns}" />
                    </Style>
                </toolkit:DataGridComboBoxColumn.EditingElementStyle>
            </toolkit:DataGridComboBoxColumn>


推荐答案

问题是单元格保持编辑模式,直到您离开单元格并且更改已提交
我在 AutoCommitComboBoxColumn

The problem is that the cell remains in Edit mode until you leave the cell and the changes are committed I posted more details in AutoCommitComboBoxColumn

解决方案:您需要创建自己的列类型以覆盖默认行为
代码:

Solution: you need to create your own column type to override the default behavior code:

public class AutoCommitComboBoxColumn : Microsoft.Windows.Controls.DataGridComboBoxColumn
{
    protected override FrameworkElement GenerateEditingElement(Microsoft.Windows.Controls.DataGridCell cell, object dataItem)
    {
        var comboBox = (ComboBox)base.GenerateEditingElement(cell, dataItem);
        comboBox.SelectionChanged += ComboBox_SelectionChanged;
        return comboBox;
    }

    public void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        CommitCellEdit((FrameworkElement)sender);
    }
}

这篇关于WPFToolkit DataGrid:Combobox列不会立即更新selectedvaluebinding的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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