Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XAML WPF
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 22:55pm
Comments
Pheonyx at 18-Jun-13 3:58am
   
Where is the XAML for your button declaration?
sandra_tay at 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
good
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.
  Permalink  
Comments
sandra_tay at 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 at 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 at 18-Jun-13 4:17am
   
Yes, I define this within the user control.
Pheonyx at 18-Jun-13 4:21am
   
Can you show the complete XAML for the user control please?
sandra_tay at 18-Jun-13 4:21am
   
I have try again, its work, thank you so much
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 325
1 Sergey Alexandrovich Kryukov 289
2 CPallini 275
3 DamithSL 260
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 18 Jun 2013
Copyright © CodeProject, 1999-2014
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