Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug "Button" can not accept "MouseLeftButtonDown" message
7 replies. Latest Post by StefanWick on October 28, 2008.
(0)
Nenong
Member
21 points
15 Posts
08-06-2008 1:22 AM |
"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";}
johnnystock
Contributor
2295 points
362 Posts
08-06-2008 6:02 AM |
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.
Skute
222 points
156 Posts
08-06-2008 8:30 AM |
The ToggleButton class can be used to switch between 2 different states if that's what you need.
08-07-2008 4:57 AM |
Oh, thank you~ ~.
Before I don't know this event is moved away.
Dastei
49 points
20 Posts
08-07-2008 7:08 AM |
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; } }
RichardP
8 points
6 Posts
10-07-2008 12:26 PM |
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.
lexin
2 points
1 Posts
10-28-2008 1:50 AM |
I install the Silverlight 2.0 release. Deaf on this event also. Dunno when it will be back and whether it can be back.
StefanWick
2864 points
438 Posts
10-28-2008 2:06 AM |
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