samedi 9 mai 2015

ScrollViewer not working with MouseWheel on GroupBox

I am trying to get a scrollviewer to work in a custom styled groupbox. This is the style for the groupbox:

<ResourceDictionary xmlns="http://ift.tt/o66D3f"
                xmlns:x="http://ift.tt/mPTqtT">

<!--Set default style of groupbox-->
<Style TargetType="GroupBox">
    <Setter Property="Margin" Value="0, 10, 0, 0"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="GroupBox">
                <Border CornerRadius="4" BorderThickness="1" BorderBrush="{StaticResource BorderBrush}" Background="{StaticResource ContentBackgroundBrush}">
                    <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                        <StackPanel Orientation="Vertical" CanVerticallyScroll="True">
                            <Label Content="{TemplateBinding Header}" Margin="5,5,0,0" Style="{StaticResource SmallTitle}"></Label>
                            <ContentPresenter Margin="10, 5, 10, 10" RecognizesAccessKey="True" x:Name="CtlGroupboxPresenter" />
                        </StackPanel>
                    </ScrollViewer>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

The scrollbar shows up, but I can't scroll using the mouse wheel. It works however when my mouse if over the vertical scrollbar. It seems like a tracking issue.

I saw some guys on SO that suggest adding some code to code behind to get it working, but as this is in a resource dictionary I have no place where I could put it...

Does anyone know what the issue is?

Here is an image of the wpf form: enter image description here

Aucun commentaire:

Enregistrer un commentaire