[英]Windows Store App ListView
我有一个ListView,它的项目是一组RadioButtons,当我从第一个项目中选择要说的单选按钮时,ListView绑定到100个字符串的列表,也许第二个和第三个项目一切正常。 但是,当我滚动到第50个项目时,或者当我在没有出现在第一页的任何项目中选择单选按钮时,只是取消选择了在前一页中的第一个项目,就好像listview再次渲染了这些项目并忘了可能的操纵
<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", };
我猜您的问题是所有RadioButton
都具有相同的GroupName
。 单选按钮的默认GroupName
为null,因此所有RadioButtons
都具有相同的GroupName
。 要解决此问题,您需要为ListView
每个项目提供唯一的GroupName
。 此外,所有“已Checked
属性都绑定到同一属性。 您是否要使用CheckBox
而不是RadioButton
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.