【问题标题】:SelectedValuePath does not return an idSelectedValuePath 不返回 id
【发布时间】:2016-04-30 14:33:53
【问题描述】:

嘿,我有一个关于从 ContactType 获取 ContactTypeId 的问题。这是具有 id 的对象:

public class ContactType
{
    public int ContactTypeId { get; set; }

    public string ContactTypeValue { get; set; }

    public int ContactId { get; set; }

    public DateTime? Added { get; set; }
    public DateTime? Updated { get; set; }
    public DateTime? Deleted { get; set; }

}

我编写了一个带有列表框的 WPF 应用程序。

<ComboBox x:Name="ContactTypeComboBox" HorizontalAlignment="Left"     Margin="110,68,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding ContactTypes}" DisplayMemberPath="ContactTypeValue" SelectedValuePath="ContactTypeId"  />

如果我得到 Selected 值路径不提供来自该对象的 ContactTypeId。它只给出一个字符串“ContactTypeId”

请帮我从 ContactType 获取一个 ContactTypeId

【问题讨论】:

标签: wpf data-binding


【解决方案1】:

SelectedValuePath 告诉控件如何深入到选定的项目并提取一个值。所选项目的值(在本例中为 ContactTypeId)公开为 SelectedValue。这就是您要读取的属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2016-12-13
    • 2017-06-20
    • 2018-07-13
    • 1970-01-01
    • 2021-05-30
    • 2017-09-13
    相关资源
    最近更新 更多