How to create a Button in WPF

<Button/>

 

The Width and Height attributes of the Button element represent the width and the height of a Button. The Content property of the Button element sets the text of a button. The x:Name attribute represents the name of the control, which is a unique identifier of a control. You may also use the Name property to set the name of a control.

 

The code snippet in Listing 1 creates a Button control and sets the name, height, width, and content of a Button control.

 

<Button x:Name="DrawCircleButton" Height="40" Width="120"

                Content="Draw Circle" >

</Button>

Listing 1

The default property of a button is Content. The following code snippet creates the same button as created by Listing 1.

<Button x:Name="DrawCircleButton" Height="40" Width="120" >

                 Draw Circle

</Button>