散分求帮助,ListBox中添加Checkbox,数据项多时,会出现莫名其妙的勾选错乱
模拟器截图:
对应XAML:
<!--ContentPanel - 在此处放置其他内容-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox Height="380" Margin="12,91,0,0" Name="listBox1" VerticalAlignment="Top" SelectionMode="Multiple">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<CheckBox x:Name="cbx_state" Tag="{Binding}"/>
<TextBlock x:Name="txt_string" Text="{Binding}" VerticalAlignment="Center" FontSize="34" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Height="66" HorizontalAlignment="Left" Margin="12,491,0,0" Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" Width="438" />
</Grid>
后端初始化ListBox内容代码:
namespace PhoneApp4.UIs
{
public partial class MultiListBox3 : PhoneApplicationPage
{
public MultiListBox3()
{
InitializeComponent();
listBox1.ItemsSource = new List<string>() { "Option 1", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6" };
}
运行截图,手动勾选了option1和option2:
往下一拉,莫名其妙的option4被选中了
再拉回最顶上,option1的变成未选中状态了,邪门了
在手机上运行也是这样的情况,只勾选一个不会出现错乱,勾选2个或以上,ListBox的滚动条再动一动,选项就莫名其妙的错乱了
[解决办法]
应该ui虚拟化问题,你去掉应该就没有,至于在虚拟情况下使用我也在研究
[解决办法]
这确实是一个已知的问题。
在blend里的listbox上右键,edit addtional template-> edit itemspanel-> create empty.
就可以了。