wpf Button.MouseLeftButtonDown doesnt work at all

Stav Alfi picture Stav Alfi · Apr 2, 2014 · Viewed 19k times · Source

Im trying to learn how MouseLeftButtonDown works but no seccuss until now.

When i click on the button, nothing heppends.

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel Name="sss">
            <Button x:Name="b1" Height="213" MouseLeftButtonDown="sss_MouseDown"/>
        </StackPanel>
    </Grid>
</Window>

Code behind is :

private void sss_MouseDown(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("3   ->>>>>" + ((Control)sender).Name);
        }

Answer

Avinash patil picture Avinash patil · Apr 2, 2014

try simple PreviewMouseLeftButtonDown event