Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've also made some further research - that if you reenter the page with LLS everything is updated correct - Visual tree has that many elements like collection. I've modified an example (<a href="http://sdrv.ms/169kRqI" rel="nofollow">http://sdrv.ms/169kRqI</a> ):</p> <p>Let's make Main_Page the second_page:</p> <p>Xaml:</p> <pre><code>&lt;phone:PhoneApplicationPage.Resources&gt; &lt;DataTemplate x:Key="ElementStyle"&gt; &lt;TextBlock x:Name="elemBlck" Text="Element"/&gt; &lt;/DataTemplate&gt; &lt;/phone:PhoneApplicationPage.Resources&gt; &lt;Grid x:Name="LayoutRoot" Background="Transparent"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="30*"/&gt; &lt;RowDefinition Height="30*"/&gt; &lt;RowDefinition Height="30*"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="70*"/&gt; &lt;ColumnDefinition Width="30*"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Button x:Name="addBtn" Content="Add" Grid.Row="0" Grid.Column="1"/&gt; &lt;Button x:Name="delBtn" Content="Del" Grid.Row="1" Grid.Column="1"/&gt; &lt;Button x:Name="showBtn" Content="Show" Grid.Row="2" Grid.Column="1"/&gt; &lt;phone:LongListSelector x:Name="phoneLLS" HorizontalAlignment="Left" Height="700" Margin="0" Grid.Row="0" VerticalAlignment="Top" Grid.RowSpan="3" Grid.Column="0" Width="300" LayoutMode="Grid" GridCellSize="300,100" IsGroupingEnabled="False" ItemTemplate="{StaticResource ElementStyle}" ItemsSource="{Binding}"/&gt; &lt;/Grid&gt; </code></pre> <p>code behind:</p> <pre><code>public partial class second_page : PhoneApplicationPage { public second_page() { InitializeComponent(); phoneLLS.DataContext = MainPage.collection; addBtn.Click += addBtn_Click; delBtn.Click += delBtn_Click; showBtn.Click += showBtn_Click; } private void addBtn_Click(object sender, RoutedEventArgs e) { MainPage.collection.Add("element"); } private void delBtn_Click(object sender, RoutedEventArgs e) { MainPage.collection.RemoveAt(MainPage.collection.Count - 1); } private void showBtn_Click(object sender, RoutedEventArgs e) { List&lt;TextBlock&gt; controlList = new List&lt;TextBlock&gt;(); SearchForControls&lt;TextBlock&gt;(phoneLLS, ref controlList); } private static void SearchForControls&lt;T&gt;(DependencyObject parent, ref List&lt;T&gt; controlList) where T : DependencyObject { int numberOfChildreen = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i &lt; numberOfChildreen; i++) { var child = VisualTreeHelper.GetChild(parent, i); if (child is T) controlList.Add((T)child); else SearchForControls&lt;T&gt;(child, ref controlList); } } } </code></pre> <p>and Main_Page - only navigation:</p> <p>Xaml:</p> <pre><code>&lt;Grid x:Name="LayoutRoot" Background="Transparent"&gt; &lt;Button x:Name="goToPage" Content="SecondPage" Width="Auto" Height="Auto" HorizontalAlignment="Center" VerticalAlignment="Center"/&gt; &lt;/Grid&gt; </code></pre> <p>Code behind:</p> <pre><code>public partial class MainPage : PhoneApplicationPage { public static ObservableCollection&lt;string&gt; collection = new ObservableCollection&lt;string&gt;(); public MainPage() { InitializeComponent(); goToPage.Click+=goToPage_Click; } private void goToPage_Click(object sender, RoutedEventArgs e) { NavigationService.Navigate(new Uri("/second_page.xaml", UriKind.Relative)); } } </code></pre> <p>Just try to do the same with and without reentering the page:</p> <ol> <li><p>add for example 3 elements, with debugger toggle a breakpoint at second line of showBtn_Click and Click the buton - it will show 6 elements! Do not touch anything except go back.</p></li> <li><p>Reenter the second page - you will se the correct LLS - with 3 elements as you click showBtn with breakpoint you will see 3 elements in the Visual Tree.</p> <p>Anybody tried this?</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload