Krm Str
Krm Str

Reputation: 11

WPF MouseDown bubbling event doesn't bubble when clicking left button

I have such XAML:

<Window x:Class="TreeViewTestingWPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="500" Width="400">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Column="0" VerticalAlignment="Center" MouseDown="Control_MouseDown">
            <Button x:Name="button1" Width="80" Height="50" MouseDown="Control_MouseDown" Margin="10" >
                <Ellipse Width="30" Height="30" Fill="Red" MouseDown="Control_MouseDown" />
            </Button>
        </StackPanel>
        <TextBlock x:Name="textBlock1" Grid.Column="1" Padding="10" />
    </Grid>
</Window>

And metod "Control_MouseDown()":

private void Control_MouseDown(object sender, MouseButtonEventArgs e)
        {
            textBlock1.Text = textBlock1.Text + "sender: " + sender.ToString() + "\n";
            textBlock1.Text = textBlock1.Text + "source: " + e.Source.ToString() + "\n\n";
        }

Everything goes good when I click on red ellipse using right button or wheel, I get such expected result:

pic 1

But when I use left button event doesn't bubble and I get only this:

pic 2

Why do everything goes this way?

UPD Frenchy says that propably Click event "eats" MouseDown is it possible to avoid such behavior?

Upvotes: 1

Views: 599

Answers (1)

Frenchy
Frenchy

Reputation: 17037

when i use PreviewMouseDown all seems ok

    <StackPanel Grid.Column="0" VerticalAlignment="Center" PreviewMouseDown="Control_MouseDown">
        <Button x:Name="button1" Width="80" Height="50" PreviewMouseDown="Control_MouseDown" Margin="10" >
            <Ellipse Width="30" Height="30" Fill="Red" PreviewMouseDown="Control_MouseDown" />
        </Button>
    </StackPanel>

Upvotes: 1

Related Questions