我在绑定RadioButton的时候遇到这样一个问题,不知道要怎么解决。请大家帮我看看。
我做的是一个心理测试窗口,所有题目的答案都只有五种,没有 很轻 中等 偏重 严重!
我从库中读出题目绑定,但是当页面出现滚动条的时候,选中的答随滚动条的滚动乱跳。
比如说我1-10题都选的是:没有 这个答案,当我滚动滚动条的时候,这些答案会跳到其它题目中,可能是后面11-20中,反正是随机乱跳到别的题中去。自己刚才的1-10题可能有的还在选中,有的就没有选中了。
下面是我的代码。<Window x:Class="Modules.诊断评估.WPFUI.xlcs心理测试_SCL90"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:igDP="http://infragistics.com/DataPresenter"
        Title="xlcs心理测试_" WindowStyle="None" WindowState="Maximized" WindowStartupLocation="CenterScreen" 
xmlns:igEditors="http://infragistics.com/Editors">
<Window.Resources>
<Style x:Key="myCustomFieldCell" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">                        <StackPanel Orientation="Horizontal" x:Name="stackPanel"  VirtualizingStackPanel.IsVirtualizing="False">
                           
                            <RadioButton Content="没有" Name="radio01" Margin="0,3,0,3" Checked="radio01_Checked"/>
                            <RadioButton Content="很轻" Name="radio02" Margin="6,3,0,3" Checked="radio02_Checked"/>
                            <RadioButton Content="中等" Name="radio03" Margin="9,3,0,3" Checked="radio03_Checked"/>
                            <RadioButton Content="偏重" Name="radio04" Margin="12,3,0,3" Checked="radio04_Checked"/>
                            <RadioButton Content="严重" Name="radio05" Margin="13,3,0,3" Checked="radio05_Checked"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>

<Grid Name="grid">
<Grid.RowDefinitions>
<RowDefinition Height="10*"/>
<RowDefinition Height="40*"/>
</Grid.RowDefinitions>
<Grid Name="operateGrid" Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="8*"/>
<RowDefinition Height="5*"/>
<RowDefinition Height="5*"/>
<RowDefinition Height="8*"/>
<RowDefinition Height="5*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Label Content="所在单位:" Name="institutionLabel" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right"/>
<igEditors:XamTextEditor Name="institutionEditor" Grid.Row="1" Grid.Column="2" IsReadOnly="True"/>
<Label Content="姓名:" Name="nameLabel" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Right"/>
<igEditors:XamTextEditor Name="nameEditor" Grid.Row="1" Grid.Column="4" IsReadOnly="True"/>
<Label Content="测试类型:" Name="testNameLabel" Grid.Row="1" Grid.Column="5" HorizontalAlignment="Right"/>
<igEditors:XamTextEditor Name="testNameEditor" Grid.Row="1" Grid.Column="6" IsReadOnly="True"/>
<Button Content="完成测试" Name="button1" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="2" Click="button1_Click"/>
</Grid>
<igDP:XamDataGrid Name="xamDataGrid1" Margin="0" Grid.Row="1">
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False"/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:FieldLayout.Fields>
<igDP:Field Name="序号" Label="序号" Width="10*"/>
<igDP:Field Name="题目标题" Label="题目标题" Width="40*"/>
<!--<igDP:Field Name="所属因子" Label="所属因子" Width="200"/>-->
<igDP:Field Name="所属因子" Label="答案" Width="50*">
<igDP:Field.Settings>
<igDP:FieldSettings CellValuePresenterStyle="{StaticResource myCustomFieldCell}"/>
</igDP:Field.Settings>
</igDP:Field>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
</Grid>
</Window>

解决方案 »

  1.   

    楼主,我看了一下你的xaml,你说你用到了帮定,但是我找遍了里面都没找到一个'Binding',你是怎么把数据绑上去的?
      

  2.   

    我建议的方式:Model-View-ViewModel (MVVM pattern) + simple xaml layout and data binding = handle this easily and elegantly.
      

  3.   

    楼上说的很对,我看不出任何绑定的Xaml代码.
    贴更详细的代码上来也许能更好的回答你的问题.
      

  4.   

    datagrid中添加VirtualizingStackPanel.IsVirtualizing="False"