[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

WPF not firing events

Ilyas

7/3/2008 7:41:00 AM

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?
3 Answers

Pavel Minaev

7/3/2008 9:09:00 AM

0

On Jul 3, 11:41 am, Ilyas <il...@igsoftwaresolutions.co.uk> 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.

Chris Jobson

7/3/2008 7:03:00 PM

0

"Ilyas" <ilyas@igsoftwaresolutions.co.uk> 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


The PHANTOM

4/5/2009 1:11:00 PM

0

1 Proud American wrote:
> Mike C. wrote:
> > Cyberiade.it Anonymous Remailer wrote:
> >
> >
> >> Translation: We got our rent-a-nigger just like we planned and
> >> the liberal media will scream racist at every opportunity.
> >>
> >
> > When you're that blatant about it, sure.
> >
> >
> >
> >
> What is the difference in Obama being a blatant racist and any one else ?
> Fact : He belongs to a racist church. Well he did until his political
> career moved him away. Here is the philosophy he goes by "If God is not
> for us and against white people," writes Cone, "then he is a murderer,
> and we had better kill him. The task of black theology is to kill gods
> who do not belong to the black community."
>
> Fact : Obama embraced the racist president of Brazil as his good friend.
> quote " thats my man right there. I love this guy "
> http://www.youtube.com/watch?v=4... This is the guy who said
> about whites and the economy �This crisis was caused by the irrational
> behavior of white people with blue eyes...."
>
> Fact : Obama has an obsession with race and the way in which whites hate
> blacks. His favorite author ids Malcom X . These are two traits of a
> racist.
>
> On top of it all he hates America which is the worse thing he can do.
> His whole book Dreams from my father is a story of his hatred of
> America. Just read that crap. He talks of his love for America but in
> his book is page after page of nothing but trash talk on America . Not
> one single good word does he say .
>
> He is a racist American hating Muslim.

Yeah,that might be true BUT DICK CHENEY WORKED FOR HALLIBURTON !!!!