Note that there are some explanatory texts on larger screens.

plurals
  1. POGet reference to my WPF ListBox's ScrollViewer in C#?
    text
    copied!<p>I think this should be easy but I'm having a tough time with it.</p> <p>How can I get a reference to my ListBox's scrollviewer in C#? I've tried pretty much everything I can think of. The ListBox is in a WPF Custom Control so we use Template.FindName to get references to all our controls. My ListBox looks like this:</p> <pre><code>&lt;ListBox x:Name="PART_SoundList" ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Hidden" Focusable="False" FocusVisualStyle="{x:Null}" HorizontalAlignment="Center" VerticalAlignment="Bottom" BorderThickness="0" ItemContainerStyleSelector="{StaticResource ListBoxItemAlternatingStyleSelector}" ItemsSource="{Binding}" &gt; &lt;ListBox.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;WrapPanel Orientation="Vertical" Height="850" Focusable="False" Panel.ZIndex="999" &gt; &lt;WrapPanel.RenderTransform&gt; &lt;TransformGroup&gt; &lt;ScaleTransform CenterX="0" CenterY="0" ScaleX=".75" ScaleY=".57" /&gt; &lt;/TransformGroup&gt; &lt;/WrapPanel.RenderTransform&gt; &lt;/WrapPanel&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ListBox.ItemsPanel&gt; &lt;ListBox.Template&gt; &lt;ControlTemplate&gt; &lt;ScrollViewer x:Name="Scroller" VerticalAlignment="Bottom" Focusable="False" Style="{StaticResource HorizontalScroller}" &gt; &lt;ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Focusable="False" Panel.ZIndex="999" /&gt; &lt;/ScrollViewer&gt; &lt;/ControlTemplate&gt; &lt;/ListBox.Template&gt; &lt;/ListBox&gt; </code></pre> <p>Template.FindName("Scroller",this) as ScrollViewer results in null.</p> <p>Any ideas? </p>
 

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