Hello WPF
How to get this code going: Create a Windows Presentation Foundation project named HelloWPF and paste the following code in the specified file.
Paste this code into Window1.xaml:
<Window x:Class="HelloWPF.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Button Height="23" Margin="96,50,107,0" Name="button1" VerticalAlignment="Top" Click="button1_Click">Say Hello!</Button>
<Label Margin="84,115,74,119" Name="label1"></Label>
</Grid>
</Window>
Paste this code into Window1.xaml.cs:
using System.Windows;
namespace HelloWPF
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
label1.Content = "Hello WPF!";
}
}
}
Compile and run.
|