如何禁用列表框项目 Wp8 的虚拟化
How to disable Virtualizing for lisbox item Wp8
我无法在列表框的 VirtualizingStackPanel 下禁用虚拟化 属性。我只得到 VirtualizationMode 属性。
实际上我需要在 listbox.Tried 几种方法下获取复选框元素,但我得到了最合适的答案
但我得到的 ItemContainerGenerator 为 null。
经过更多的研究,我发现我需要设置 IsVirtualizing=false 来获取 ItemContainerGenerator 。
xaml 是 ::
<ListBox x:Name="my_list" Grid.Row="0">
<ItemsControl.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>
</ItemsControl.ItemTemplate>
</ListBox>
我无法获取 VirtualizingStackPanel.isvertualing property.I 正在尝试获取 cbx_state。
我已经用这种方式完成了,我从 C# 中选中了复选框
在 Page1.xaml:
<phone:PhoneApplicationPage
x:Class="PhoneApp3.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid Background="AliceBlue">
<ListBox x:Name="my_list" Height="200" Grid.Row="0">
<ItemsControl.ItemTemplate >
<DataTemplate >
<StackPanel Orientation="Horizontal" >
<CheckBox x:Name="cbx_state" Tag="{Binding BindsDirectlyToSource=True}"/>
<TextBlock x:Name="txt_string" Text="{Binding BindsDirectlyToSource=True}" VerticalAlignment="Center" FontSize="34" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
</Grid>
在page1.cs
namespace PhoneApp3
{
public partial class Page1 : PhoneApplicationPage
{
public Page1()
{
InitializeComponent();
String[] names = { "Virat", "Rohit", "Rahane", "Umesh", "Axar" };
my_list.ItemsSource = names;
this.Loaded += Page1_Loaded;
}
void Page1_Loaded(object sender, RoutedEventArgs e)
{
GetItemsRecursive(my_list);
}
private void GetItemsRecursive(DependencyObject lb)
{
var childrenCount = VisualTreeHelper.GetChildrenCount(lb);
for (int i = 0; i < childrenCount; i++)
{
var child = VisualTreeHelper.GetChild(lb, i);
if (child is CheckBox) // specific/child control
{
CheckBox targeted_element = (CheckBox)child;
targeted_element.IsChecked = true;
if (targeted_element.IsChecked == true)
{
return;
}
}
GetItemsRecursive(child);
}
}
}
}
我无法在列表框的 VirtualizingStackPanel 下禁用虚拟化 属性。我只得到 VirtualizationMode 属性。
实际上我需要在 listbox.Tried 几种方法下获取复选框元素,但我得到了最合适的答案
<ListBox x:Name="my_list" Grid.Row="0">
<ItemsControl.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>
</ItemsControl.ItemTemplate>
</ListBox>
我无法获取 VirtualizingStackPanel.isvertualing property.I 正在尝试获取 cbx_state。
我已经用这种方式完成了,我从 C# 中选中了复选框 在 Page1.xaml:
<phone:PhoneApplicationPage
x:Class="PhoneApp3.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid Background="AliceBlue">
<ListBox x:Name="my_list" Height="200" Grid.Row="0">
<ItemsControl.ItemTemplate >
<DataTemplate >
<StackPanel Orientation="Horizontal" >
<CheckBox x:Name="cbx_state" Tag="{Binding BindsDirectlyToSource=True}"/>
<TextBlock x:Name="txt_string" Text="{Binding BindsDirectlyToSource=True}" VerticalAlignment="Center" FontSize="34" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
</Grid>
在page1.cs
namespace PhoneApp3
{
public partial class Page1 : PhoneApplicationPage
{
public Page1()
{
InitializeComponent();
String[] names = { "Virat", "Rohit", "Rahane", "Umesh", "Axar" };
my_list.ItemsSource = names;
this.Loaded += Page1_Loaded;
}
void Page1_Loaded(object sender, RoutedEventArgs e)
{
GetItemsRecursive(my_list);
}
private void GetItemsRecursive(DependencyObject lb)
{
var childrenCount = VisualTreeHelper.GetChildrenCount(lb);
for (int i = 0; i < childrenCount; i++)
{
var child = VisualTreeHelper.GetChild(lb, i);
if (child is CheckBox) // specific/child control
{
CheckBox targeted_element = (CheckBox)child;
targeted_element.IsChecked = true;
if (targeted_element.IsChecked == true)
{
return;
}
}
GetItemsRecursive(child);
}
}
}
}