定义Student类,其中有布尔值属性IsNormal和IsLate,View中使用DevExpress的GridControl,将两个布尔值放入一个单元格中,以RadioButton显示,需要自定义CellTemplate,但是当进行RadioButton的Checked属性和两个布尔值进行绑定的时候总是出错,原来是数据并没有绑过去,正确的绑定方式应该是,注意
Binding RowData.Row.IsNormal
<dxg:GridControl Name="datagrid" AutoGenerateColumns="None" ShowBorder="False" CurrentItem="{Binding CurrentItem,Mode=TwoWay}" SelectedItem="{Binding SelectedItem,Mode=TwoWay}"
ItemsSource="{Binding Students}">
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True" AllowEditing="True"/>
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn Header="学号" Binding="{Binding Sid,Mode=TwoWay}"/>
<dxg:GridColumn Header="姓名" Binding="{Binding Sname,Mode=TwoWay}"/>
<dxg:GridColumn Header="性别" Binding="{Binding Sgender,Mode=TwoWay}"/>
<dxg:GridColumn Header="班级" Binding="{Binding Sclass,Mode=TwoWay}"/>
<dxg:GridColumn Header="状态">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Visibility="{Binding ElementName=dockPanel,Path=DataContext.BeforeItemsVisibility,Mode=TwoWay}">
<RadioButton Content="出勤" IsChecked="{Binding RowData.Row.IsNormal,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ElementName=dockPanel,Path=DataContext.NormalCommand}" CommandParameter="{Binding ElementName=datagrid}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
<RadioButton Content="迟到" IsChecked="{Binding RowData.Row.IsLate,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ElementName=dockPanel,Path=DataContext.LateCommand}" CommandParameter="{Binding ElementName=datagrid}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
<RadioButton Content="请假" IsChecked="{Binding RowData.Row.IsReasonable,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ElementName=dockPanel,Path=DataContext.ReasonableCommand}" CommandParameter="{Binding ElementName=datagrid}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
<RadioButton Content="旷课" IsChecked="{Binding RowData.Row.IsAbsent,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ElementName=dockPanel,Path=DataContext.AbsentCommand}" CommandParameter="{Binding ElementName=datagrid}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding ElementName=dockPanel,Path=DataContext.AfterItemsVisibility,Mode=TwoWay}">
<RadioButton Content="早退" IsChecked="{Binding RowData.Row.IsLeaved,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ElementName=dockPanel,Path=DataContext.LeavedCommand}" CommandParameter="{Binding ElementName=datagrid}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
<RadioButton Content="正常" IsChecked="{Binding RowData.Row.IsRight,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding ElementName=dockPanel,Path=DataContext.RightCommand}" CommandParameter="{Binding ElementName=datagrid}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
</StackPanel>
</StackPanel>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</dxg:GridControl.Columns>
</dxg:GridControl>
参考网址
https://www.devexpress.com/Support/Center/Question/Details/Q341304