Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

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

 
 
Old 12-30-2008   #1 (permalink)
jsnover13


 
 

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
Old 12-30-2008   #2 (permalink)
Mark Salsbery [MVP]


 
 

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

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

> 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++

Quote:

>
> 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
 

Thread Tools


Similar Threads
Thread Forum
Are sub-routines parameters called by reference or called by value? VB Script
id being requested Live Messenger
Re: Backup advice requested for Vista Ultimate Vista General
The requested resource is in use. General Discussion
Info Requested Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46