Note that there are some explanatory texts on larger screens.

plurals
  1. POSet Height of First ListBoxItem as difference of the other Items in WP7
    text
    copied!<p>i need to show a list of item in a ListBox from the bottom in WP7. So in case i have some items that the height sum of them is &lt; of ListBox Height i need to have a blank item at the top with the difference of the Height.</p> <p>I have to do this because i set the ItemSource of Listbox, so i cannot know what is the right height of all items before load them.</p> <p>In Item_loaded event of every Item i save the height and at the last i need to set the Height of the First.</p> <pre><code>&lt;ListBox x:Name="ConvListBox" Margin="0,0,-12,0" &gt; &lt;ListBox.ItemTemplate &gt; &lt;DataTemplate &gt; &lt;Grid&gt; &lt;StackPanel Name="BaloonMessage" Margin="3,0,0,0" Loaded="Baloon_Loaded" Tag="{Binding IsSentMsg}" &gt; &lt;TextBlock Name="SMSText" Text="{Binding SMSText}" Margin="7,3,8,35" TextWrapping="Wrap" Height="Auto" Width="Auto" FontSize="22" Foreground="White"/&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>I set the ItemsSource and add a blank item at top, and a blank at bottom:</p> <pre><code> ObservableCollection&lt;ClassMessaggio&gt; messaggi = new ConversazioneViewModel(MessaggioConversazione).Conversazione; ClassMessaggio FirstLineScrollMessage = new ClassMessaggio(); FirstLineScrollMessage.IsSentMsg = "3"; messaggi.Insert(0, FirstLineScrollMessage); ClassMessaggio LastLineScrollMessage = new ClassMessaggio(); LastLineScrollMessage.IsSentMsg = "2"; messaggi.Insert(messaggi.Count, LastLineScrollMessage); this.ConvListBox.ItemsSource = messaggi; </code></pre> <p>And at Item_Loaded i'm trying this:</p> <pre><code>var Panel = (StackPanel) sender; if (Panel != null) { Grid grid = (Grid)Panel.Parent; Border baloon = (Border)Panel.FindName("Baloon"); baloon.Width = grid.Width - 100; if (Panel.Tag.ToString() == "3") { TotalBaloonsHeight = 0; baloon.Background = grid.Background; baloon.Name = "FirstScrollBaloon"; } else if (Panel.Tag.ToString() == "2") { baloon.Height = 2; Panel.Height = 2; grid.Height = 2; Border FirstBaloon = (Border)ConvListBox.FindName("FirstScrollBaloon"); if (FirstBaloon != null) { FirstBaloon.Height = ConvListBox.Height - TotalBaloonsHeight; } } else { TotalBaloonsHeight = TotalBaloonsHeight + baloon.Height; } } </code></pre> <p>My problem is that this line return me always null :( </p> <pre><code> Border FirstBaloon = (Border)ConvListBox.FindName("FirstScrollBaloon"); </code></pre> <p>I hope is clear, sorry for my english. </p> <p>EDIT::</p> <p>Ok this should work:</p> <pre><code>var Baloons = LayoutRoot.GetVisualDescendants().OfType&lt;Border&gt;(); foreach (var FirstBaloon in Baloons) { if (FirstBaloon != null) { if (FirstBaloon.Name == "FirstScrollBaloon") { FirstBaloon.Height = ConvListBox.ActualHeight - TotalBaloonsHeight; break; } } } </code></pre>
 

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