WPF中Button的MouseDown路由事件

  XAML中:

<Grid>

      <Button Height="50" HorizontalAlignment="Left" Name="MyButton" VerticalAlignment="Top" Width="133" Margin="100,100,0,0" MouseDown="MyMouseDown">
            <Image Source="Images\1.jpg" Width="100"/>
           
        </Button>
</Grid>

 

cs中:

public MainWindow()
{
        InitializeComponent();
        MyButton.AddHandler(Button.MouseDownEvent, new RoutedEventHandler(MyMouseDown), true);
}

 

private void MyMouseDown(object sender, RoutedEventArgs e)
{
      MessageBox.Show("可以点击");
}

posted @ 2011-08-12 22:20  therockthe  阅读(362)  评论(0)    收藏  举报