2015-11-23 116 views
0

我试图添加一个组合框到Xceed WPF数据网格,但无法将Itemssource绑定到组合框。这是数据网格的xaml。如何绑定xceed datagrid中的组合框的Itemssource

<xwpf:DataGridControl ItemsSource="{Binding SaleDetails}" AutoCreateColumns="False" > 
     <xwpf:DataGridControl.Columns> 
      <xwpf:Column FieldName="Status" Title="Status" CellContentTemplate="{StaticResource colReinstatementType}" CellEditor="{StaticResource statusEditor}" /> 
     </xwpf:DataGridControl.Columns> 
</xwpf:DataGridControl> 

资源

<UserControl.Resources> 
    <DataTemplate x:Key="colReinstatementType"> 
      <ComboBox BorderThickness="0" 
         x:Name="cmbStatus1" 
         IsReadOnly="False" 
         IsEditable="True" 
         MinHeight="20" 
         DisplayMemberPath="part_no" 
         Text="{xwpf:CellEditorBinding NotifyOnSourceUpdated=True}" 
         SelectedItem="{Binding Item, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
         ItemsSource="{Binding AvailablePartMaterial, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> 
      </ComboBox> 
     </DataTemplate> 
     <xwpf:CellEditor x:Key="statusEditor"> 
      <xwpf:CellEditor.EditTemplate> 
       <DataTemplate> 
        <ComboBox BorderThickness="0" 
           x:Name="cmbStatus" 
           IsReadOnly="False" 
           IsEditable="True" 
           MinHeight="20" 
           DisplayMemberPath="part_no" 
           Text="{xwpf:CellEditorBinding NotifyOnSourceUpdated=True}" 
           SelectedItem="{Binding Item, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
           ItemsSource="{Binding AvailablePartMaterial, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> 
        </ComboBox> 
       </DataTemplate> 
      </xwpf:CellEditor.EditTemplate> 
     </xwpf:CellEditor>    
    </UserControl.Resources> 

ItemAvailablePartMaterial不要在SaleSheet类型,其集合绑定到DataGrid存在。即使Item属性确实被解雇,这意味着组合框的选定项目正在绑定。但是没有数据显示在组合框中。

+0

你能检查输出窗口的绑定失败日志吗? – user1672994

+0

thr在输出窗口中没有绑定失败 – WAQ

回答

2

CellContentTemplate仅用于显示目的。通常用于使用类似TextBlock的文本显示文本。在必须使用编辑器类型(例如布尔列上的CheckBox)的情况下,您需要使其成为ReadOnly以避免任何不需要的问题。

在你的情况,你有一个CellEditorBinding作为CellContentTemplate的组合框。 CellEditorBinding仅适用于CellEditor,因此如果用户使用CellContentTemplate的ComboBox编辑行值,它将不会影响基础值。

为了您的绑定,尝试这样的事情,而不是:

SelectedValuePath="part_no" // name of column used to identify which record is selected 
DisplayMemberPath="part_name" // name of column used to indicate the text/value to display 
SelectedValue = {xwpf:CellEditorBinding} // SelectedItem or SelectedIndex can be used instead, depending on the situation/data 

在问候中的ItemsSource,你不能直接当你是一个CellEditor中的的DataTemplate内绑定到它,你需要表明它位于何处。例如:

ItemsSource="{Binding Source={x:Static Application.Current}, Path=MyData}"> 
相关问题