Note that there are some explanatory texts on larger screens.

plurals
  1. POFind control inside Listbox.ItemTemplate (WPF C#)
    primarykey
    data
    text
    <p>I have some problems finding the right <code>TextBlock</code> control inside a <code>StackPanel</code>. My markup:</p> <pre><code>&lt;ListBox Name="lstTimeline" ItemContainerStyle="{StaticResource TwItemStyle}" MouseDoubleClick="lstTimeline_MouseDoubleClick"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;DockPanel MaxWidth="{Binding ElementName=lstTimeline, Path=ActualWidth}"&gt; &lt;Border Margin="10" DockPanel.Dock="Left" BorderBrush="White" BorderThickness="1" Height="48" Width="48" HorizontalAlignment="Center"&gt; &lt;Image Source="{Binding ThumbNail, IsAsync=True}" Height="48" Width="48" /&gt; &lt;/Border&gt; &lt;StackPanel Name="stkPanel" Margin="10" DockPanel.Dock="Right"&gt; &lt;TextBlock Text="{Binding UserName}" FontWeight="Bold" FontSize="18" /&gt; &lt;TextBlock Text="{Binding Text}" Margin="0,4,0,0" FontSize="14" Foreground="#c6de96" TextWrapping="WrapWithOverflow" /&gt; &lt;TextBlock Text="{Binding ApproximateTime}" FontSize="14" FontFamily="Georgia" FontStyle="Italic" Foreground="#BBB" /&gt; &lt;TextBlock Text="{Binding ScreenName}" Name="lblScreenName" FontSize="14" FontFamily="Georgia" FontStyle="Italic" Foreground="#BBB" Loaded="lblScreenName_Loaded" /&gt; &lt;/StackPanel&gt; &lt;/DockPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>My double click code:</p> <pre><code>private void lstTimeline_MouseDoubleClick(object sender, MouseButtonEventArgs e) { ListBoxItem lbi = (lstTimeline.SelectedItem as ListBoxItem); StackPanel item = lbi.FindName("stkPanel") as StackPanel; if (item != null) MessageBox.Show("StackPanel null"); TextBlock textBox = item.FindName("lblScreenName") as TextBlock; if (textBox != null) MessageBox.Show("TextBlock null"); MessageBox.Show(textBox.Text); } </code></pre> <p>But the <code>StackPanel</code> is null. How do find the right <code>TextBlock</code> in <code>SelectedItem</code>?</p> <p>Thanks for your help.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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