【问题标题】:Combo box not populating even though displaymemberpath is not null即使 displaymemberpath 不为空,组合框也不会填充
【发布时间】:2017-09-09 22:39:58
【问题描述】:

自从我尝试将 itemsource 设置为等于 datagrid 项目源以来 只想显示一次“un”属性。我还在 xaml 中为组合框设置了绑定属性,并返回类引用。调试时它正确设置了显示成员路径,但是当我运行它时它没有显示在组合框中。

 private void dgViewCBIData_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
           cbi= (CBICalculate)dgViewCBIData.SelectedItem;
            txtName.Text = cbi.Name.ToString();
            txtHeight.Text = cbi.He.ToString();
            txtWeight.Text = cbi.We.ToString();
            cmbUnits.DisplayMemberPath = cbi.Un;  


        }

【问题讨论】:

    标签: c# .net wpf


    【解决方案1】:

    DisplayMemberPath 属性应该设置为string,用于标识要在ComboBox 中显示的属性的名称。

    因此,如果您有一个名为Un 的属性并希望显示该属性的值,则应将DisplayMemberPath 设置为string“Un”:

    cmbUnits.DisplayMemberPath = "Un";  
    

    【讨论】:

      猜你喜欢
      • 2021-04-26
      • 2013-12-23
      • 1970-01-01
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 1970-01-01
      相关资源
      最近更新 更多