Page view counter
"Button" can not accept "MouseLeftButtonDown" message
Last post 10-28-2008 2:06 AM by StefanWick. 7 replies.
Sort Posts:
08-06-2008 1:22 AM
"Button" can not accept "MouseLeftButtonDown" message

"Button" can not accept "MouseLeftButtonDown" /"MouseLeftButtonUp"message, why??

<UserControl x:Class="TerryLee.SilverlightDemo14.Page"
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="500" Height="240">
    <Canvas Background="#46461F">
        <Button
           MouseLeftButtonDown="OnMouseDown"
           MouseMove="OnMouseMove"
           MouseLeftButtonUp="OnMouseUp"
           Canvas.Left="50" Canvas.Top="50" 
           Width="160" Height="80">
        </Button>
        <TextBlock x:Name="TBShow" Text="111" Canvas.Left="0" Canvas.Top="0" Width="100" Height="100"/>
    </Canvas>
</UserControl>


void OnMouseDown(object sender, MouseButtonEventArgs e)
{
    TBShow.Text = "OnMouseDown";
}
void OnMouseMove(object sender, MouseEventArgs e)
{
}
void OnMouseUp(object sender, MouseButtonEventArgs e)
{
    TBShow.Text = "OnMouseUp";
}

Nenong

Loading...
Joined on 08-06-2008
Posts 15
08-06-2008 6:02 AM
Marked as Answer
Re: "Button" can not accept "MouseLeftButtonDown" message

In Beta 2 the Mouse:eftButtonDown event was removed from the button and similar controls since they also had the more appropriate Click event.  If you change to Click you should be fine.

John Stockton
RIA Developer at Ascentium
Co-Author of Silverlight 2 in Action

blog

johnnystock

Loading...
Joined on 01-10-2008
Bellevue, WA
Posts 329
08-06-2008 8:30 AM
Re: "Button" can not accept "MouseLeftButtonDown" message

The ToggleButton class can be used to switch between 2 different states if that's what you need.

 

Skute

Loading...
Joined on 05-27-2006
UK
Posts 152
08-07-2008 4:57 AM
Re: "Button" can not accept "MouseLeftButtonDown" message

Oh, thank you~ ~.

Before I don't know this event is moved away.

Nenong

Loading...
Joined on 08-06-2008
Posts 15
08-07-2008 7:08 AM
Marked as Answer
Re: "Button" can not accept "MouseLeftButtonDown" message

 You can override this behavior and define your own button that fired mousedown and mouseup

 

 

    /// <summary>
    /// Quick hack to remove event handling that mark events as handled
    /// </summary>
    public class Button : System.Windows.Controls.Button
    {
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            e.Handled = false;
        }

        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonUp(e);
            e.Handled = false;
        }
    }
  

Regards,
David Steinkopff

Dastei

Loading...
Joined on 07-23-2008
Rosenheim, Bavaria, Germany
Posts 20
10-07-2008 12:26 PM
Re: "Button" can not accept "MouseLeftButtonDown" message

Switching to the click event only works if you don't need to get the mouse position in your click event.  I know you can capture the mouse move and record the position but there are cases such when the user might not move there mouse before clicking your button.  The example that comes to mind is if a combobox is open and you move your mouse over the top of the button to be clicked.  The first click closes the combobox and the second click would trigger the click event of the button without ever recording the mouseposition in the mouse move event.   MSFT needs to let us have the MouseLeftButtonDown back in the final release.

RichardP

Loading...
Joined on 04-17-2008
Posts 4
10-28-2008 1:50 AM
Re: "Button" can not accept "MouseLeftButtonDown" message

I install the Silverlight 2.0 release. Deaf on this event also.  Dunno when it will be back and whether it can be back.

lexin

Loading...
Joined on 10-28-2008
Posts 1
10-28-2008 2:06 AM
Re: "Button" can not accept "MouseLeftButtonDown" message

This behavior is by design and the solution was already posted in this thread: If you want to handle the MouseLeftButtonDown event on a button you can derive from button and handle the event there (or just unmark the 'Handled' flag).

Thanks, Stefan Wick

Microsoft Silverlight

Microsoft Silverlight | http://blogs.msdn.com/swick/

StefanWick

Loading...
Joined on 06-15-2007
Microsoft
Posts 212
Microsoft Communities