Wpf 如何在xceed datagrid中绑定combobox的Itemssource
我正在尝试向Xceed WPF数据网格添加组合框,但无法将Itemssource绑定到组合框。下面是datagrid的xamlWpf 如何在xceed datagrid中绑定combobox的Itemssource,wpf,combobox,datagrid,xceed,xceed-datagrid,Wpf,Combobox,Datagrid,Xceed,Xceed Datagrid,我正在尝试向Xceed WPF数据网格添加组合框,但无法将Itemssource绑定到组合框。下面是datagrid的xaml <xwpf:DataGridControl ItemsSource="{Binding SaleDetails}" AutoCreateColumns="False" > <xwpf:DataGridControl.Columns> <xwpf:Column FieldName="Status" T
<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>
商品
和可用零件材料
确实存在于其集合绑定到数据网格的销售单
类型中。即使是Item
属性也会被激发,这意味着组合框的选定项被绑定。但组合框中不显示任何数据 CellContentTemplate仅用于显示目的。通常,它用于使用文本块之类的东西显示文本。在必须使用编辑器类型(例如布尔列上的复选框)的情况下,您需要将其设置为只读,以避免任何不必要的问题
在本例中,您有一个组合框,其中CellEditorBinding作为CellContentTemplate。CellEditorBinding仅在CellEditor中工作,因此,如果用户使用CellContentTemplate的组合框编辑行的值,它将不会影响基础值
对于绑定,请尝试以下操作:
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}">
您可以检查输出窗口中的绑定失败日志吗?输出窗口中没有绑定失败