Windows phone 8 如何禁用lisbox项目Wp8的虚拟化

Windows phone 8 如何禁用lisbox项目Wp8的虚拟化,windows-phone-8,checkbox,listbox,Windows Phone 8,Checkbox,Listbox,我无法禁用listbox的VirtualizationStackPanel下的虚拟化属性。我只获取VirtualizationMode属性。 实际上,我需要在listbox下获取checkbox元素。尝试了几种方法,但得到了最合适的ans 但我得到的ItemContainerGenerator为空。 经过更多的rnd之后,我发现我需要设置isVirtualization=false来获取ItemContainerGenerator。 xaml是: <ListBox x:Name="my_l

我无法禁用listbox的VirtualizationStackPanel下的虚拟化属性。我只获取VirtualizationMode属性。 实际上,我需要在listbox下获取checkbox元素。尝试了几种方法,但得到了最合适的ans 但我得到的ItemContainerGenerator为空。 经过更多的rnd之后,我发现我需要设置isVirtualization=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>


我无法获取VirtualzingStackPanel.isvertualing属性。我试图获取cbx_状态。

我以这种方式从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>

在第1.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);
        }
    }
}
 }
名称空间PhoneApp3
{
公共部分类第1页:PhoneApplicationPage
{
公共页1()
{
初始化组件();
字符串[]名称={“Virat”、“Rohit”、“Rahane”、“Umesh”、“Axar”};
my_list.ItemsSource=名称;
this.Loaded+=Page1_Loaded;
}
无效页面1_已加载(对象发送器,路由目标e)
{
GetItemsRecursive(我的列表);
}
私有void GetItemsRecursive(DependencyObject lb)
{
var childrenCount=visualtreeheloper.GetChildrenCount(lb);
for(int i=0;i
您的问题是您必须选中c#code中的复选框,对吗?是的,尝试了一种方法……但在使用它时,ItemContainerGenerator显示为空值,我发现这是由于isvertualing属性设置为true造成的……我必须将其设置为false才能获得它所说的要设置的ItemContainerGeneratorvirtualizangstackpanel.isvertualing=false我无法获取。isvertualing property在@Arun.P上运行得很好,我想这样做……几周来我一直在尝试,非常感谢。只需在DependencyObject child=VisualTreeHelper.GetChild(lb,i)上做一点更改;而不是var子代