Click here to Skip to main content
15,567,002 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can attach an event to a WPF button like this:

<Button Click="Button_Click"/>

So why can't I do this:



Just when I thought I was beginning to understand WPF. :(

What I have tried:

Tried searching the internet but I get loads of tutorials on writing my own DependencyProperty code.
Updated 14-Sep-16 3:54am

1 solution

Because the property element syntax[^] only applies to properties, not events. It's primarily intended for cases where you can't represent the property value as a string, so you can't use the attribute syntax[^].

Event handlers can only be specified as the handler method name, so there's no need for an element-syntax equivalent for them. Even if there was, the syntax you've proposed isn't valid XML.

NB: You can bind the button's Command property[^] using the property element syntax, although it's not normally required.
Share this answer
Patrick Skelton 14-Sep-16 10:08am    
Thank you for a very thorough explanation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900