简体   繁体   English

Windows应用商店列表视图

[英]Windows Store App ListView

I've a ListView that its items are a set of RadioButtons, the ListView is bonded to a list of 100 strings when I select a radio button let say from the first item , and maybe the second and the third, everything work just fine. 我有一个ListView,它的项目是一组RadioButtons,当我从第一个项目中选择要说的单选按钮时,ListView绑定到100个字符串的列表,也许第二个和第三个项目一切正常。 But when I scroll for the maybe the 50th item or when I select a radiobutton in any item not appearing the first page, the selection of the first item which are in the previous page is just deselected, as if the listview rendered the items again and forgot about may manipulation 但是,当我滚动到第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", };

I'm guessing your problem is that all of your RadioButton s have the same GroupName . 我猜您的问题是所有RadioButton都具有相同的GroupName The default GroupName for radio buttons is null, so all your RadioButtons have the same GroupName . 单选按钮的默认GroupName为null,因此所有RadioButtons都具有相同的GroupName To fix this you need to come up with a unique GroupName for each item in your ListView . 要解决此问题,您需要为ListView每个项目提供唯一的GroupName Also, all of your Checked properties are bound to the same property. 此外,所有“已Checked属性都绑定到同一属性。 Are you maybe wanting a CheckBox instead of a RadioButton ? 您是否要使用CheckBox而不是RadioButton

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM