问题代码:
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
<dxg:GridControl Name="datagrid" AutoGenerateColumns="None" ShowBorder="False" CurrentItem="{Binding CurrentItem,Mode=TwoWay}" SelectedItem="{Binding SelectedItem,Mode=TwoWay}"
ItemsSource="{Binding Students}" Height="2000">
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True" AllowEditing="True" VerticalScrollbarVisibility="Hidden"/>
</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="状态">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<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}"/>
</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}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
</StackPanel>
</StackPanel>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</dxg:GridControl.Columns>
</dxg:GridControl>解决方案:
在该GridControl的外层再套一个ScrollViewer,然后禁用GridControl的VerticalScrollBar,设置GridControl的给定高度。这样拉动滚动条里面的内容不会重新渲染,数据也就不会丢失了。然而带来的问题是,滚动后标题行也会滚动,看下面的时候就看不见标题行了,此问题暂未解决;通过后台代码设置选中行后自动滚动到选中行,代码及解决方案如下:
设置外层ScrollViewer CanContentScroll="True",然后在后台设置焦点grid.View.Focus();
<ScrollViewer CanContentScroll="True">
<dxg:GridControl Name="datagrid" AutoGenerateColumns="None" ShowBorder="False" CurrentItem="{Binding CurrentItem,Mode=TwoWay}" SelectedItem="{Binding SelectedItem,Mode=TwoWay}"
ItemsSource="{Binding Students}" Height="2000">
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True" AllowEditing="True" VerticalScrollbarVisibility="Hidden"/>
</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="状态">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<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}"/>
</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}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
</StackPanel>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</dxg:GridControl.Columns>
</dxg:GridControl>
</ScrollViewer>
DevExpress的GridControl中自定义列中使用RadioButton在拉动滚动条后数据丢失的解决方法,布布扣,bubuko.com
DevExpress的GridControl中自定义列中使用RadioButton在拉动滚动条后数据丢失的解决方法
原文:http://blog.csdn.net/luopotaotao/article/details/21227509