我有一个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", };
答案 0 :(得分:0)
我猜你的问题是你的所有RadioButton
都有相同的GroupName
。单选按钮的默认GroupName
为空,因此您的所有RadioButtons
都具有相同的GroupName
。要解决此问题,您需要为GroupName
中的每个项目选择一个唯一的ListView
。此外,您的所有Checked
属性都绑定到同一属性。您是否想要CheckBox
而不是RadioButton
?