Cannot get EventSetter to work

If my understanding is correct you use EventSetters to assign handlers to events in Styles. I cannot get an event setter to work.

<StyleTargetType="{x:Type Button}">

<EventSetterEvent="Click"Handler="ButtonClickEventHandler"></EventSetter>

</Style>

This will not compile. It says 'The Handler attribute is not declared', although if I access the EventSetter object from c# it clearly has a 'Handler' property. How can you assign handlers to events in a style?

-Ryan

[1781 byte] By [RyanF] at [2007-12-21]
# 1

I not able to test now but why don't you try this:

<Style TargetType="{x:Type Button}">

<EventSetter Event="Click"></EventSetter>

</Style>

ThomasLEBRUN at 2007-9-10 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2
And how is that a solution or an answer to the original question?
MarcLaroche at 2007-9-10 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3

My 3rd party opinion is that it doesn't answer/resolve your question.

You could just reference the same handler in every button declaration

<Button Click="ButtonClickEventHandler" </Button>

but I'm guessing that the reasons you're using a style is to avoid that.

NIK

NickNotYet at 2007-9-10 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4
Yes, thats what i'm trying to avoid, although it certainly does work of course.
RyanF at 2007-9-10 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 5

I not able to test now but why don't you try this:

<Style TargetType="{x:Type Button}">

<EventSetter Event="Click"></EventSetter>

</Style>

That doesn't include the event handler.

RyanF at 2007-9-10 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 6
someone must know how EventSetter works.
RyanF at 2007-9-10 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 7

I have code exactly like your original sample that both compiles and works as expected.

It may have somthing to do with the location of your style declaration.

NIK

NickNotYet at 2007-9-10 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified