DevExpress中自定义CellTemplate数据绑定不显示的问题

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值