WPF - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

WPF Button

WPF Button Control

shape Introduction

In this article, I am going to explain about “Button Control and its Functionality”. Button Control is one of the most used control. Without button control, it’s hard to do anything.Button Control’s default event is Click event. Button Control have named and Text properties. We can also change the appearance of the button using Font size, Background Color  Properties.
Follow the below steps to know about the button functionality.
  • Create a new window.
  • Now go to xamal source and write the following code:
[csharp] <Window x:Class="WPFBtton.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WPF | Button Control" Height="350" Width="525" Background="LightCyan"> <Grid> <Button Content="WPF Button" HorizontalAlignment="Left" Margin="153,130,0,0" VerticalAlignment="Top" Width="198" Height="50" FontSize="25" FontStretch="UltraCondensed" RenderTransformOrigin="0.5,0.5" Background="Pink"> <Button.RenderTransform> <TransformGroup> <ScaleTransform ScaleY="1" ScaleX="1"/> <SkewTransform AngleY="0" AngleX="0"/> <RotateTransform Angle="0"/> <TranslateTransform X="2" Y="2"/> </TransformGroup> </Button.RenderTransform> </Button> </Grid> </Window> [/csharp]
Now run the application, then we should get the result like below: Double click on the button, then the click event is raised. Now, write the code as below to display a message after button click. [csharp] private void Button_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Welcome to SPlessons"); } }[/csharp]
Press F5 or Start to run the application. Click on the WPF button, then it shows a message box. Below figure shows the output.



WPF - Related Information
WPF Calendar Control
WPF Overview
WPF Simple Application
WPF ComboBox
WPF Treeview


Join us on - Telegram Channel