WPF:使用 DataGridComboBoxColumn 进行数据绑定

发布于 2024-09-11 07:36:24 字数 661 浏览 0 评论 0原文

这就是我想要的:

  • 有一个组合框列绑定到 ClassA 的 ApplicationKey 属性
  • 该组合框由静态函数 all 中的 ApplicationToken 填充。
  • 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}}"/>

This is what I want:

  • There is a combo-box column bound to the ApplicationKey property of ClassA
  • The combo-box is populated with ApplicationTokens from a static function all.
  • An ApplicationToken has a ApplicationName and ApplicationKey property
  • When an item is selected in the drop-down, the ClassA.ApplicationKey property is set to the ApplicationToken.ApplicationKey on the selected item.

This is my current code, which populates the combobox but doesn't update ClassA.ApplicationKey.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欢你一世 2024-09-18 07:36:24

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

工作示例

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

Use SelectedValueBinding instead of SelectedItemBinding when using SelectedValuePath.

Working example

<DataGridComboBoxColumn 
    Header="Application" 
    SelectedValueBinding="{Binding ApplicationKey}"
    SelectedValuePath="ApplicationKey" 
    DisplayMemberPath="ApplicationName" 
    ItemsSource="{Binding Source={x:Static app:ApplicationLookup.GetAllOrNone}}"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文