Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 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
Comments
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.

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


In XAML the event is "Click" not "OnClick" as it was in windows forms.
 
Share this answer
 
Comments
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
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.
 
Share this answer
 

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