将Combobox绑定到Datatable WPF时出错

时间:2018-02-13 12:38:28

标签: c# wpf datatable combobox

我们正试图让我们的组合框绑定到Datatable。 Out数据表由两列“Kommune Navn”和“Kommune Nr”组成,但是对于每一行,我们都会收到以下错误:

System.Windows.Data Error: 40 : BindingExpression path error: 'Kommune Nr' property not found on 'object' ''DataRowView' (HashCode=50916928)'. BindingExpression:Path=Kommune Nr; DataItem='DataRowView' (HashCode=50916928); target element is 'ComboBox' (Name=''); target property is 'NoTarget' (type 'Object')

我们的组合框:

<ComboBox 

                DisplayMemberPath="Kommune Navn"
                SelectedValuePath="Kommune Nr"
                ItemsSource="{Binding KommuneNavne}"
                SelectedValue="{Binding kommuneNr, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                 Margin="3"
                />

我们的Viewmodel:

private DataTable _kommuneNavne;

public DataTable KommuneNavne
    {
        get { return _kommuneNavne; }
        set
        {
            _kommuneNavne = value;
            OnPropertyChanged(nameof(KommuneNavne));
        }
    }

0 个答案:

没有答案
相关问题