Silverlight MouseLeftButtonDown event not firing

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-03-27T03:08:19Z Indexed on 2010/03/27 3:13 UTC
Read the original article Hit count: 1170

For the life of me, I can not get this to work. I can get MouseEnter, MouseLeave, and Click events to fire, but not MouseLeftButtonDown or MouseLeftButtonUp.

Here's my XAML

    <UserControl x:Class="Dive.Map.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
        <Canvas x:Name="LayoutRoot" MouseLeftButtonDown="LayoutRoot_MouseLeftButtonDown">
            <Button x:Name="btnTest" Content="asdf" Background="Transparent"  MouseLeftButtonDown="btnTest_MouseLeftButtonDown"></Button>
        </Canvas>
    </UserControl>

And here's my code

public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void btnTest_MouseLeftButtonDown( object sender, MouseButtonEventArgs e )
    {
        btnTest.Content = DateTime.Now.ToString();
    }

    private void LayoutRoot_MouseLeftButtonDown( object sender, MouseButtonEventArgs e )
    {
        e.Handled = false;
    }
}

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about event-handling