Datagrid组合框中的WPF SelectedItem

时间:2014-04-15 15:07:50

标签: c# wpf xaml datagrid combobox

我有以下代码,但是我想知道当我从组合框中选择一个项目时如何获得SelectedItem。我试图在与****一致的情况下这样做,但这不起作用,我相信它很接近,任何建议都会很棒。感谢

<DataGridComboBoxColumn SelectedItemBinding="{Binding Name}">
<DataGridComboBoxColumn.EditingElementStyle>
    <Style TargetType="ComboBox">
        <Setter Property="ItemsSource"
                Value="{Binding DataContext.AnotherCollection,
                           RelativeSource={RelativeSource Mode=FindAncestor, 
                                                     AncestorType=Window}}"/>
        <Setter Property="DisplayMemberPath" Value="Name"/>
    </Style>
</DataGridComboBoxColumn.EditingElementStyle>
<DataGridComboBoxColumn.ElementStyle>
    <Style TargetType="ComboBox">
        <Setter Property="ItemsSource"
                Value="{Binding DataContext.AnotherCollection,
                          RelativeSource={RelativeSource Mode=FindAncestor, 
                                                     AncestorType=Window}}"/>
        <Setter Property="DisplayMemberPath" Value="Name"/>

  *****<Setter Property="SelectedItem" Value="{Binding SelectedCustomer, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></Setter>****

    </Style>
</DataGridComboBoxColumn.ElementStyle>

我确实收到了这个错误:

  

System.Windows.Data错误:40:BindingExpression路径错误:   'object'上找不到'SelectedCustomer'属性   '' CustomerEligibility_D45A565716CF82DEEF89311760E7DDA725D9D002B7ED3873BE0158121BBE9D52'   (的HashCode = 20202357)”。 BindingExpression:路径= SelectedCustomer;   的DataItem = 'CustomerEligibility_D45A565716CF82DEEF89311760E7DDA725D9D002B7ED3873BE0158121BBE9D52'   (的HashCode = 20202357); target元素是'TextBlockComboBox'(Name ='');   target属性是'SelectedItem'(类型'Object')

ViewModel中的属性是

 private CustomerEligibility m_Name = null;

    public CustomerEligibility SelectedCustomer
    {
        get { return m_Name; }
        set
        {
            m_Name = value;


            OnPropertyChanged("SelectedCustomer");
        }
    }

0 个答案:

没有答案