1

我有一个 ListView,它的项目是一组 RadioButtons,当我从第一个项目中选择一个单选按钮时,ListView 绑定到 100 个字符串的列表,也许是第二个和第三个,一切正常。但是,当我滚动到第 50 个项目时,或者当我在没有出现第一页的任何项目中选择一个单选按钮时,上一页中的第一个项目的选择只是被取消选择,好像列表视图再次呈现了这些项目并且忘记了可能的操纵

        <ListView ItemsSource="{Binding}" x:Name="list" VirtualizingStackPanel.VirtualizationMode="Standard">
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <RadioButton Template="{StaticResource CheckBoxTemplate2}" Foreground="Orange" Content="Test" Label="YOK" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,0,0" Canvas.ZIndex="12" FontSize="14" FontWeight="Bold" FontFamily="Advantage-SemiBold"  Checked="BetRadioButton_Checked_1" Click="x1_Click"  />
                    <RadioButton x:Name="x2" Template="{StaticResource CheckBoxTemplate2}" Foreground="Orange" Content="Test" Label="YOK" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,0,0" Canvas.ZIndex="12" FontSize="14" FontWeight="Bold" FontFamily="Advantage-SemiBold"  Checked="BetRadioButton_Checked_1" Click="x1_Click"  />
                    <RadioButton x:Name="x3" Template="{StaticResource CheckBoxTemplate2}" Foreground="Orange" Content="Test" Label="YOK" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,0,0" Canvas.ZIndex="12" FontSize="14" FontWeight="Bold" FontFamily="Advantage-SemiBold"  Checked="BetRadioButton_Checked_1"  Click="x1_Click"  />
                    <RadioButton x:Name="x4" Template="{StaticResource CheckBoxTemplate2}" Foreground="Orange" Content="Test" Label="YOK" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,0,0" Canvas.ZIndex="12" FontSize="14" FontWeight="Bold" FontFamily="Advantage-SemiBold"  Checked="BetRadioButton_Checked_1"  Click="x1_Click"  />
                    <RadioButton x:Name="x5" Template="{StaticResource CheckBoxTemplate2}" Foreground="Orange" Content="Test" Label="YOK" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,0,0" Canvas.ZIndex="12" FontSize="14" FontWeight="Bold" FontFamily="Advantage-SemiBold"  Checked="BetRadioButton_Checked_1"  Click="x1_Click"  />
                    <RadioButton x:Name="x6" Template="{StaticResource CheckBoxTemplate2}" Foreground="Orange" Content="Test" Label="YOK" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,0,0" Canvas.ZIndex="12" FontSize="14" FontWeight="Bold" FontFamily="Advantage-SemiBold"  Checked="BetRadioButton_Checked_1"  Click="x1_Click"  />
                    <RadioButton x:Name="x7" Template="{StaticResource CheckBoxTemplate2}" Foreground="Orange" Content="Test" Label="YOK" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,0,0" Canvas.ZIndex="12" FontSize="14" FontWeight="Bold" FontFamily="Advantage-SemiBold"  Checked="BetRadioButton_Checked_1"  Click="x1_Click"  />

                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>



list.DataContext = new List<String>() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", };
4

1 回答 1

0

我猜你的问题是你所有的RadioButtons 都一样GroupName。单选按钮的默认GroupName值为 null,因此您RadioButtons的所有按钮都具有相同的GroupName. 要解决此问题,您需要GroupNameListView. 此外,您的所有Checked属性都绑定到同一个属性。你可能想要 aCheckBox而不是 aRadioButton吗?

于 2012-10-31T21:33:00.183 回答