Step 1: Create an empty WPF using Visual Studio, enter the name for the application and click on OK
Step 2: Create a button using the following code or drag and drop a button from the ToolBox of Visual Studio 2013.
Code:
- <Button Content="Button" HorizontalAlignment="Left" Margin="133,120,0,0" VerticalAlignment="Top" Width="75"/>
Step 3: Name the button content and double click on the button, you will be getting this window
Enter the following code to make you click event activated with message box:
- MessageBox.Show("hI How are you");
So the entire code of MainWindow.xaml.cs should be as below:
- using System;
- usingSystem.Collections.Generic;
- usingSystem.Linq;
- usingSystem.Text;
- usingSystem.Threading.Tasks;
- usingSystem.Windows;
- usingSystem.Windows.Controls;
- usingSystem.Windows.Data;
- usingSystem.Windows.Documents;
- usingSystem.Windows.Input;
- usingSystem.Windows.Media;
- usingSystem.Windows.Media.Imaging;
- usingSystem.Windows.Navigation;
- usingSystem.Windows.Shapes;
- namespacemessageapp
- {
-
-
-
- publicpartialclassMainWindow: Window
- {
- publicMainWindow()
- {
- InitializeComponent();
- }
- privatevoidButton_Click(object sender, RoutedEventArgs e)
- {
- MessageBox.Show("hI How are you");
- }
- }
- }
Now run the WPF application: