Search This Blog

Wednesday, October 30, 2013

WPF Button

WPF > Controls  > ContentControl > Button

WPF Button represents a Windows button control.
The main event is Click event.

WPF Button Example:

XAML:

<Window x:Class="ButtonExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBox x:Name="txt1" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBox" Width="215" Margin="0,27,0,220"/>
        <Button x:Name="btn1" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="btn1_Click"/>
    </Grid>
</Window>

C# Code:

private void btn1_Click(object sender, RoutedEventArgs e)
{
   txt1.Text = "Button was clicked";
}  



Other examples: