views:

32

answers:

1

According to a post at the very end of this thread you can replace the ScrollViewer of a ListBox with a ContentPresenter to disable scrolling in a nested scenario.

However, I don't know how to replace the ScrollViewer. Do I have to re-create the template?

+1  A: 

Yes, you'll need to assign your own template but you'll be using an ItemsPresenter, not ContentPresenter. The default template for ListBox includes a ScrollViewer wrapped around its ItemsPresenter. By making a copy of the template you can just remove the ScrollViewer and leave the rest of the template (and behavior) intact. This is the default template without the ScrollViewer (you can also remove the IsGrouping Trigger if you want):

<ControlTemplate TargetType="{x:Type ListBox}">
    <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true">
        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
        </Trigger>
        <Trigger Property="IsGrouping" Value="true">
            <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>
John Bowen
Works great. Thanks!
Scott Whitlock