WPF:使用 DataGridComboBoxColumn 进行数据绑定(bind)

标签 wpf data-binding binding wpfdatagrid datagridcomboboxcolumn

这就是我要的:

  • 有一个组合框列绑定(bind)到 ClassA
  • 的 ApplicationKey 属性
  • 组合框由静态函数 all 中的 ApplicationTokens 填充。
  • ApplicationToken 具有 ApplicationName 和 ApplicationKey 属性
  • 在下拉列表中选择项目时,ClassA.ApplicationKey 属性设置为所选项目的 ApplicationToken.ApplicationKey。

  • 这是我当前的代码,它填充组合框但不更新 ClassA.ApplicationKey。
    <DataGridComboBoxColumn 
        Header="Application" 
        SelectedItemBinding="{Binding ApplicationKey, Converter={gui:DebugConverter}}" 
        SelectedValuePath="ApplicationKey" 
        DisplayMemberPath="ApplicationName" 
        ItemsSource="{Binding Source={x:Static app:ApplicationLookup.GetAllOrNone}}"/>
    

    最佳答案

    使用 SelectedValuePath 时使用 SelectedValueBinding 而不是 SelectedItemBinding。

    工作示例

    <DataGridComboBoxColumn 
        Header="Application" 
        SelectedValueBinding="{Binding ApplicationKey}"
        SelectedValuePath="ApplicationKey" 
        DisplayMemberPath="ApplicationName" 
        ItemsSource="{Binding Source={x:Static app:ApplicationLookup.GetAllOrNone}}"/>
    

    关于WPF:使用 DataGridComboBoxColumn 进行数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3337802/

    相关文章:

    c# - 单击时 WPF DataGrid 给出 ArgumentOutOfRangeException

    c# - WPF ListView SelectedItems 数据绑定(bind) MVVM

    WPF - 以 jpeg 格式保存 Canvas 的黑色背景

    multithreading - 核心数据和多线程(和绑定(bind)让它更有趣)

    wpf - 在 WPF 中更改 View 时,ViewModel 中的文本框值未更新

    angularjs - 如何动态统计ng-repeat重复了多少次?

    c# - 如果数据库表更新/插入,如何让 Windows C# 控件自动更新?

    c# - 如何使用 MVVM 将不同列表绑定(bind)到每行中的 DataGridComboBoxColumn

    ssl - Windows 8 : SSL certificate binding fails both programmatically and through netsh

    wpf - 当 BindingExpression 使用数组索引时,已删除对象的 DataGrid 绑定(bind)错误