【问题标题】:Radio button in Gridcolumn won't trigger bindingGridcolumn 中的单选按钮不会触发绑定
【发布时间】:2020-01-08 03:03:08
【问题描述】:

我有两个 devexpress 网格列,每个列都有一个单选按钮。

在我为绑定到单选按钮的属性设置值时,在后面的代码中,绑定需要。但是当我在视图中更改选定的单选按钮时,选定的不会触发该属性。

我错过了什么?

<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>

【问题讨论】:

    标签: c# wpf radio-button devexpress gridcontrol


    【解决方案1】:

    问题的原因很可能是您尝试使用非 DX 控件作为 GridColumn 的编辑,而 DevExpress 明确不鼓励这样做。例如,尝试用 DX-CheckEdit 替换 RadioButton。

    我的经验总结:

    1. 请勿将非 DX 控件用作 GridControl 的 InplaceEdits。
    2. 让 DX 编辑在 CellTemplate 中分配时能够正常工作 他们的名字必须设置为“PART_Editor”。省略会导致导航等问题。
    3. 使用GridColumn.FieldName-property 代替绑定。这应该使 InplaceEdit 自动从其 Column 继承绑定。

    【讨论】:

      【解决方案2】:

      IsChecked 的绑定更改为RowData.Row.IsOrder,它可能会解决您的选择问题。您可以阅读更多关于使用 RowData.Row 而非 ValueData here 的信息。

      另一方面,正如@Sancho Panza 所说,在处理 CellTemplate 时,您总是最好坚持使用 BaseEdit 后代。

      这是在CellTemplate 中使用 BaseEdit 后代的优势之一:

      对于 DevExpress 数据编辑器(BaseEdit 类的后代),您可以将编辑器的 Name 属性设置为 PART_Editor。在这种情况下,GridControl 会自动调整其外观并将编辑器与 ColumnBase.FieldName 或 ColumnBase.Binding 属性指定的源字段同步。
      您可以将任何绑定与名为 PART_Editor 的编辑器一起使用。在这种情况下,GridControl 获取/设置编辑器值的逻辑被禁用。

      使用 BaseEdit 后代或 WPF RadioButton 的最终决定权在您,但我也建议坚持使用 BaseEdit。

      【讨论】:

        猜你喜欢
        • 2019-09-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-05
        • 1970-01-01
        • 1970-01-01
        • 2013-06-25
        相关资源
        最近更新 更多