Silverlight MouseLeftButtonDown event not fired

I ran into a problem when in Silverlight the MouseLeftButtonDown event does not fire for Button and hyperlinkButton. It seems like it is being processed somewhere in the framework. How can I override this behavior

In the XAML code below. When I click the Named Cancel button, Button_MouseLeftButtonDown does not start. I tried putting a text block inside the button, MouseLeftButtonDown works when I click on the text on the button, but it does not bubble up to the frame

    <Button Name="Cancel" ClickMode="Release" MouseLeftButtonDown="Button_MouseLeftButtonDown">
            <Button.Content>
                <TextBlock Name="CancelInnerText" MouseLeftButtonDown="TextBlock_MouseLeftButtonDown">Clone Page</TextBlock>
            </Button.Content>

+3
source share
4 answers

To work, you had to set ClickMode = "Hover" for the button. The MouseLeftButtonDown event now fires and also bubbles

+7
source

, , . - , , ?

:

    <Button Name="Cancel" Click="Button_Click">
        <Button.Content>
            <TextBlock>Clone Page</TextBlock>
        </Button.Content>
    </Button>
0

! , ? ,

, - . ( , ). mousebuttondown base.Focus();

: MouseLeftButtonDown , .

, ( ):

public class InAction : ContentControl
{
    public InAction()
    {
        this.DefaultStyleKey = typeof(InAction);
        this.MouseLeftButtonDown += new MouseButtonEventHandler(InAction_MouseLeftButtonDown);
    }

    void InAction_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        base.Focus();   
    }
}
0

you can call the AddHandler method for the MouseLeftButtonDown event (as indicated below) and the event will fire in your code.

button1.AddHandler(Button.MouseLeftButtonDownEvent, new  ouseButtonEventHandler(button1_MouseLeftButtonDown), true);

private void button1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
        // your code
}
0
source

Source: https://habr.com/ru/post/1725194/


All Articles