I want to create button that always has the same behaviour (close window). Can I add this behaviour to a template?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Templates in WPF are used for layout and data. I am assuming you are looking to attach your code-behind actions to the button template. This won’t be done through a template. Instead, you probably want to look at building a custom control. This way you can put your code-behind and your button together.
Here is an article on WPF templates and how they work:
http://wpf.2000things.com/tag/templates/
Here is a forum post on rolling your own button custom control:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a81ed36b-c9d1-4619-96e2-4025b919819c/
Finally, here is a good article from MSDN on all of these issues:
http://msdn.microsoft.com/en-us/magazine/cc163421.aspx