HitTestMode on DockPanel and panels with 100% width

Hello everyone. I had a question on HitTestMode works

<DockPanel Margin="5,10">
    <StackPanel Orientation="Vertical" Dock="Left"
        Clicked="{goToViewAccountPage}" Width="100%"
        HitTestMode="LocalVisualAndChildren">
        <Text FontSize="12" Value="Hello World"/>
        <Text FontSize="12" Value="Hello Programmer"/>
    </StackPanel>

    <Panel Alignment="Top" Text="EDIT" Dock="Right"
            HitTestMode="LocalBoundsAndChildren"
            Clicked="{goToEditAccountPage}" MinWidth="100" />
</DockPanel>

On the code snippet above I have a DockPanel which encloses two panels in it.

The first panel is a StackPanel which holds two text fields, once the this panel is clicked it should activate the goToViewAccountPage function.

The second panel is a button that should activate the goToEditAccountPage.

But what is happening when a click the second panel its activating goToViewAccountPage function.

Please help!!!

We strongly recommend posting complete reproductions, since testing little snippets of code without seeing how you use them is extremely ineffective and prone to missing important details. Without a complete repro, you’re also limiting our ability to explain why things work in a particular way, when interacting with their parent containers etc.

That said, the problem in this case is that you’re not using DockPanel right (100% width on a child within one?). And it’s not even related to HitTestMode. Here’s something that should work fine:

<DockPanel Margin="5,10">
    <Panel Dock="Right" HitTestMode="LocalBounds" Clicked="{goToEditAccountPage}" MinWidth="100" Color="#18f" />
    <StackPanel Orientation="Vertical" Clicked="{goToViewAccountPage}" HitTestMode="LocalVisualAndChildren">
        <Text FontSize="12" Value="Hello World"/>
        <Text FontSize="12" Value="Hello Programmer"/>
    </StackPanel>
</DockPanel>

Sadly, I don’t have the possibility to be fully certain that it works, because as explained above, I don’t see how you’re using it.

Hope this helps!