Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Thu, 3 Jul 2008 00:41:16 -0700 (PDT),    group: microsoft.public.dotnet.framework        back       


WPF not firing events   
Hi all

I have the following xaml

    <UniformGrid MouseDown="UniformGrid_MouseDown">
        <Button Name="btn0">Hello</Button>
        <Button Name="btn1">
            <Button.Template>
                <ControlTemplate>
                    <Rectangle Fill="Red" Stroke="Yellow"
Opacity="0.7" StrokeThickness="5"></Rectangle>
                </ControlTemplate>
            </Button.Template>
        </Button>
        <Button Name="btn2">
            <Button.Template>
                <ControlTemplate>
                    <Ellipse Fill="Green" Stroke="Violet"
Opacity="0.7" StrokeThickness="5"></Ellipse>
                </ControlTemplate>
            </Button.Template>
        </Button>
    </UniformGrid>
and the following code for the code behind

        private void UniformGrid_MouseDown(object sender,
MouseButtonEventArgs e)
        {
            FrameworkElement elm = e.OriginalSource as
FrameworkElement;
            MessageBox.Show("You clicked " + elm.Name);
        }

Why is it that the events are never raised? I want to catch all button
mousedown events (ideally I would like to catch the click event for
buttons) in a global handler...how do i do this?
date: Thu, 3 Jul 2008 00:41:16 -0700 (PDT)   author:   Ilyas

Re: WPF not firing events   
On Jul 3, 11:41 am, Ilyas  wrote:
> Hi all
>
> I have the following xaml
>
>     <UniformGrid MouseDown="UniformGrid_MouseDown">
>         <Button Name="btn0">Hello</Button>
>         <Button Name="btn1">
>             <Button.Template>
>                 <ControlTemplate>
>                     <Rectangle Fill="Red" Stroke="Yellow"
> Opacity="0.7" StrokeThickness="5"></Rectangle>
>                 </ControlTemplate>
>             </Button.Template>
>         </Button>
>         <Button Name="btn2">
>             <Button.Template>
>                 <ControlTemplate>
>                     <Ellipse Fill="Green" Stroke="Violet"
> Opacity="0.7" StrokeThickness="5"></Ellipse>
>                 </ControlTemplate>
>             </Button.Template>
>         </Button>
>     </UniformGrid>
> and the following code for the code behind
>
>         private void UniformGrid_MouseDown(object sender,
> MouseButtonEventArgs e)
>         {
>             FrameworkElement elm = e.OriginalSource as
> FrameworkElement;
>             MessageBox.Show("You clicked "  elm.Name);
>         }
>
> Why is it that the events are never raised? I want to catch all button
> mousedown events (ideally I would like to catch the click event for
> buttons) in a global handler...how do i do this?

This is because MouseDown is a "bubbling" event - it means that child
control on which the event happens handles it first, and only if it
declines to handle it, the event is passed on to the parent of that
control (and so on, until it reaches top). If you want to capture the
event in a parent before the child sees it, you need to use a
"tunneling" event - in your case, it would be PreviewMouseDown.
date: Thu, 3 Jul 2008 02:09:29 -0700 (PDT)   author:   Pavel Minaev

Re: WPF not firing events   
"Ilyas"  wrote in message 
news:3c848a1b-a981-4f44-9e68-98d6452398a0@34g2000hsf.googlegroups.com...
> Hi all
>
> I have the following xaml
>
>    <UniformGrid MouseDown="UniformGrid_MouseDown">
>        <Button Name="btn0">Hello</Button>
>        <Button Name="btn1">
>            <Button.Template>
>                <ControlTemplate>
>                    <Rectangle Fill="Red" Stroke="Yellow"
> Opacity="0.7" StrokeThickness="5"></Rectangle>
>                </ControlTemplate>
>            </Button.Template>
>        </Button>
>        <Button Name="btn2">
>            <Button.Template>
>                <ControlTemplate>
>                    <Ellipse Fill="Green" Stroke="Violet"
> Opacity="0.7" StrokeThickness="5"></Ellipse>
>                </ControlTemplate>
>            </Button.Template>
>        </Button>
>    </UniformGrid>
> and the following code for the code behind
>
>        private void UniformGrid_MouseDown(object sender,
> MouseButtonEventArgs e)
>        {
>            FrameworkElement elm = e.OriginalSource as
> FrameworkElement;
>            MessageBox.Show("You clicked " + elm.Name);
>        }
>
> Why is it that the events are never raised? I want to catch all button
> mousedown events (ideally I would like to catch the click event for
> buttons) in a global handler...how do i do this?

As an alternative to the approach suggested by Pavel, you can see events 
even if they have already been handled. Try adding the line
    AddHandler(FrameworkElement.MouseDownEvent, new 
MouseButtonEventHandler(UniformGrid_MouseDown), true);
to your window's constructor after the call to InitializeComponent (and 
remove "MouseDown="UniformGrid_MouseDown" from the XAML).

Chris Jobson
date: Thu, 3 Jul 2008 20:03:18 +0100   author:   Chris Jobson

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us