如何禁用lisbox项Wp8的虚拟化 [英] How to disable Virtualizing for lisbox item Wp8
问题描述
我无法禁用VirtualizingStackPanel的列表框下的Virtualizing属性。我只获得VirtualizationMode属性。
其实我需要在listbox.Tried下面获取checkbox元素。但是最合适的方法是我得到这里
,但我得到ItemContainerGenerator为null。
更多rnd后,我发现我需要设置IsVirtualizing = false来获取ItemContainerGenerator。
xaml is ::
< ListBox x:Name =my_listGrid.Row =0> ;
< ItemsControl.ItemTemplate>
< StackPanel Orientation =Horizontal>
< CheckBox x:Name =cbx_stateTag ={Binding}/>
< TextBlock x:Name =txt_stringText ={Binding}VerticalAlignment =CenterFontSize =34/>
< / StackPanel>
< / DataTemplate>
< /ItemsControl.ItemTemplate>
< / ListBox>
我无法获取VirtualizingStackPanel.isvertualing属性。我试图获取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 =PortraitOrientation =Portrait
mc:Ignorable =d
shell:SystemTray.IsVisible =True>
<! - LayoutRoot是放置所有页面内容的根网格 - >
< Grid Background =AliceBlue>
< ListBox x:Name =my_listHeight =200Grid.Row =0>
< ItemsControl.ItemTemplate>
< DataTemplate>
< StackPanel Orientation =Horizontal>
< CheckBox x:Name =cbx_stateTag ={Binding BindsDirectlyToSource = True}/>
< TextBlock x:Name =txt_stringText ={Binding BindsDirectlyToSource = True}VerticalAlignment =CenterFontSize =34/&
< / StackPanel>
< / DataTemplate>
< /ItemsControl.ItemTemplate>
< / ListBox>
< / Grid> $ page $。
命名空间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是CheckBox)//特定/子控件
{
CheckBox targeted_element =(CheckBox)child;
targeted_element.IsChecked = true;
if(targeted_element.IsChecked == true)
{
return;
}
}
GetItemsRecursive(child);
}
}
}
}
I am not able to disable the Virtualizing property under VirtualizingStackPanel for listbox .I am only getting VirtualizationMode property. Actually i need to get checkbox element under listbox.Tried several methods but most appropriate ans i got here but i was getting ItemContainerGenerator as null. After more rnd i found that i need to set IsVirtualizing=false to get the ItemContainerGenerator . xaml is ::
<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>
I am not able to get VirtualizingStackPanel.isvertualing property.I was trying to get cbx_state.
I have done in this manner i got check box checked from c# In 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>
in 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);
}
}
}
}
这篇关于如何禁用lisbox项Wp8的虚拟化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!