Click here to Skip to main content
13,049,172 members (66,390 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I'm trying to write an click event for save button. However, when I write in xaml, there is no OnClick function or Click function for me.

So, how can write an event for the button to perform some action?
Posted 17-Jun-13 21:55pm
Pheonyx 18-Jun-13 3:58am
Where is the XAML for your button declaration?
sandra_tay 18-Jun-13 4:02am
<Button Content="Save" Height="27" Width="50"/>

this code is inside a user control that I created.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

<button content="Save" height="27" width="50" click="Button_Click" />

In XAML the event is "Click" not "OnClick" as it was in windows forms.
sandra_tay 18-Jun-13 4:08am
I have try to using "Click" but it does not having this event. And it will only show me "ClickMode"
Pheonyx 18-Jun-13 4:12am
It is definitely called Click. Where about's are you trying to define this? In the button definition within the user control, or in the main window that is hosting the user control?
sandra_tay 18-Jun-13 4:17am
Yes, I define this within the user control.
Pheonyx 18-Jun-13 4:21am
Can you show the complete XAML for the user control please?
sandra_tay 18-Jun-13 4:21am
I have try again, its work, thank you so much
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You should learn MVVM. It would seem that save should be part of the ViewModel, not part of the View. In this case you would bind a Command to a property in the ViewModel with a type of ICommand. I have done some projects using WPF, but not MVVM, and have found that it is a mistake. Much easier to maintain the MVVM pattern than to deal with directly handling events.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 18 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100