I am not able to find checkbox in listbox 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>
I am trying to get cbk_state so that i can set its checked property.The function i used to get the checkbox is
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 ListBoxItem)
{
MessageBox.Show(child.GetType().ToString());
return;
}
GetItemsRecursive(child);
}
}
The problem is that i am getting ChildrenCount as zero everytime. I have gone through several methods but no as such of use.Also tried this but here i am not getting ItemContainerGenerator for listBox.
I am new to wp8 programming plz help.Thanks
Hi got the solution here. there is no need to set virtualization property its simple.
just a bit change at DependencyObject child = VisualTreeHelper.GetChild(lb, i); instead of var child
Are you asking about getting the
Checked
property of theCheckbox
?Is this the one you were looking for?. Sample code to find the
Children
control within aParent
usingVisualTreeHelper
: