To find the Control Whether it may be a Checkbox,TextBox,Loader,ImageBrush whatever it may be By using the Following code you can find the control in LongListSelector and do respective actions like enabling,disabling,hiding etc.For Example this is my LongListSelector I need to find a control and Hide it
- <phone:LongListSelector
- x:Name="AddrBook"
- JumpListStyle="{StaticResource AddrBookJumpListStyle}"
- Background="Transparent"
- GroupHeaderTemplate="{StaticResource AddrBookGroupHeaderTemplate}"
- ItemTemplate="{StaticResource AddrBookItemTemplate}"
- LayoutMode="List"
- IsGroupingEnabled="true"
- HideEmptyGroups ="true"/>
This is my Data Template of LongListSelector.
- <DataTemplate x:Key="AddrBookItemTemplate">
- <StackPanel VerticalAlignment="Top">
- <TextBlock FontWeight="Bold" Text="{Binding FirstName}" />
- <TextBlock Text="{Binding LastName}" />
- <TextBlock Text="{Binding Address}" />
- <TextBlock Text="{Binding Phone}" />
- </StackPanel>
- </DataTemplate>
So What can I Do is I can Simply use the following code to get what control I want from the longlistselector .
Use the Below Code Wherever you wish to get Control inside LLS
- LongListSelector myControl= (AddrBook as LongListSelector);
- SearchVisualTree(myControl); //Finding The TextBlock In LongListSelector(in My Case)
- private void SearchVisualTree(DependencyObject targetElement)
- {
- var count = VisualTreeHelper.GetChildrenCount(targetElement);
- if (count == 0)
- return;
- for (int i = 0; i < count; i++)
- {
- var child = VisualTreeHelper.GetChild(targetElement, i);
- if (child is TextBlock)
- TextBlock targetItem = (TextBlock)child;
-
-
- if (targetItem.Visibility == System.Windows.Visibility.Visible)
- {
- targetItem.Visibility = System.Windows.Visibility.Collapsed;
- return;
- }
- }
- else
- {
- SearchVisualTree(child);
- }
- }
- }
Now its Done!Cheers
Thank You !