Windows Vista Forums

Advice requested - why doesn't this eventhandler get called?
  1. #1


    jsnover13 Guest

    Advice requested - why doesn't this eventhandler get called?

    I'm missing something simple.
    I want to hand craft my object hierarchy in code but I'm doing
    something wrong. This code displays properly but it does the
    MouseDown eventhandler never gets called.

    Any ideas?

    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    namespace WpfApplication1
    {
    public partial class Window1 : Window
    {
    public Window1()
    {
    InitializeComponent();
    Button b = new Button();
    b.Content = "PUSH ME";
    b.MouseDown += new MouseButtonEventHandler(b_MouseDown);
    this.Content = b;
    }



    void b_MouseDown(object sender, MouseButtonEventArgs e)
    {
    Button b = (Button)sender;
    b.Content = "Down";
    }
    }
    }

      My System SpecsSystem Spec

  2. #2


    Mark Salsbery [MVP] Guest

    Re: Advice requested - why doesn't this eventhandler get called?

    <jsnover13@xxxxxx> wrote in message
    news:de8b529a-fa72-4dcd-afc1-d9bcdcf27578@xxxxxx

    > I'm missing something simple.
    > I want to hand craft my object hierarchy in code but I'm doing
    > something wrong. This code displays properly but it does the
    > MouseDown eventhandler never gets called.
    >
    > Any ideas?

    MouseDown is being handled by the Button class.

    You could instead handle the tunneling PreviewMouseDown event instead,
    or maybe use a Button-derived class if appropriate:

    public class MyButton : Button
    {
    protected override void OnMouseDown(MouseButtonEventArgs e)
    {
    this.Content = "Down";

    base.OnMouseDown(e);
    }
    }


    By the way, a better place for WPF questions is
    http://social.msdn.microsoft.com/for...S/wpf/threads/
    This newsgroup is pretty dead

    Mark

    --
    Mark Salsbery
    Microsoft MVP - Visual C++


    >
    > using System;
    > using System.Windows;
    > using System.Windows.Controls;
    > using System.Windows.Input;
    > namespace WpfApplication1
    > {
    > public partial class Window1 : Window
    > {
    > public Window1()
    > {
    > InitializeComponent();
    > Button b = new Button();
    > b.Content = "PUSH ME";
    > b.MouseDown += new MouseButtonEventHandler(b_MouseDown);
    > this.Content = b;
    > }
    >
    > void b_MouseDown(object sender, MouseButtonEventArgs e)
    > {
    > Button b = (Button)sender;
    > b.Content = "Down";
    > }
    > }
    > }

      My System SpecsSystem Spec

Advice requested - why doesn't this eventhandler get called? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Are sub-routines parameters called by reference or called by value? Thomas Lebrecht VB Script 13 26 Mar 2009
id being requested thank you Live Messenger 1 20 Jan 2009
Re: Backup advice requested for Vista Ultimate Norman Vista General 1 16 Dec 2008
The requested resource is in use. Mark Vista General 4 20 Feb 2008
Info Requested SGB Vista General 3 18 Oct 2006