![](/img/trans.png)
[英]INotifyPropertyChanged Binding to DataTemplate in GridColumn
[英]Radio button in Gridcolumn won't trigger binding
我有两个 devexpress gridcolumns,每个都有一个单选按钮。
在后面的代码中,当我为绑定到单选按钮的属性设置一个值时,绑定会发生。 但是当我在视图中更改选定的单选按钮时,选定的不会触发该属性。
我错过了什么?
<dxg:GridColumn Binding="{Binding IsOrder}"
Header="Order"
Visible="{Binding IsVisible}"
Width="60">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<RadioButton IsChecked="{Binding Path=Value, Mode=TwoWay}"
GroupName="{Binding RowData.Row.Number}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
IsEnabled="{Binding
Path=View.DataContext.StatusNotHandled}"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
<dxg:GridColumn Binding="{Binding IsNotOrder}"
Header="Not order"
Visible="{Binding IsVisible}"
Width="60">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<RadioButton IsChecked="{Binding Path=Value, Mode=TwoWay}"
GroupName="{Binding RowData.Row.Number}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
IsEnabled="{Binding
Path=View.DataContext.StatusNotHandled}"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
问题的原因很可能是您尝试使用非 DX 控件作为 GridColumn 的编辑,这是 DevExpress 明确不鼓励的。 例如,尝试用 DX-CheckEdit 替换 RadioButton。
我的经验总结:
将IsChecked
的绑定更改为RowData.Row.IsOrder
,它可能会解决您的选择问题。 您可以在此处阅读有关在Value
或Data
上使用RowData.Row
更多信息。
另一方面,正如@Sancho Panza 所说,在处理 CellTemplate 时,最好坚持使用 BaseEdit 后代。
这是在CellTemplate中使用 BaseEdit 后代的优势之一:
对于 DevExpress 数据编辑器(BaseEdit 类的后代),您可以将编辑器的 Name 属性设置为 PART_Editor。 在这种情况下,GridControl 会自动调整其外观并使编辑器与由 ColumnBase.FieldName 或 ColumnBase.Binding 属性指定的源字段同步。
您可以将任何绑定与名为 PART_Editor 的编辑器结合使用。 在这种情况下,GridControl 获取/设置编辑器值的逻辑被禁用。
使用 BaseEdit 后代还是 WPF RadioButton 的最终决定权在您手中,但我也建议您坚持使用 BaseEdit。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.