WPF Hello World
Hello, I’m going to write a series of articles about WPF.This only pretend to be an introduction. I’m learning WPF as you, so feedback is welcome.
In order to run a WPF application you need the .NET Framework version 3.0, or greater. Windows Vista has the .NET Framework v3.0 installed by default, so you only need to install it if you have Windows XP SP2.To develop WPF applications you should have Visual Studio 2005 with the "Orcas" extensions, or a later version of Visual Studio, and also the Windows SDK.
XAML stands for eXtensible Application Markup Language. It is an all-purpose XML-based language used for declaring object graphs, which are instantiated at runtime. XAML is used by WPF developers to declare the layout of a user interface (UI), and the resources used in that UI.It is not at all necessary to use XAML when programming in WPF. Anything that can be done in XAML can also be done in code. Using XAML makes many UI development scenarios much easier and faster, such as creating the layout of a UI and configuring styles, templates, and other WPF-specific entities.
I have used Visual Studio 2008 on Windows Vista to make this applicaiton. Create a WPF Application using Visual Studion 2008
Now we have a file Window1.xaml. Replace the code with this:
<Window x:Class="WPFHelloWorld.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Hello World from WPF" Height="300" Width="300">
<Grid>
<Button Name ="btnHelloWorld" Click="btnHelloWorld_Click"
Height="60"
Margin="61,0"
VerticalAlignment="Top">Hello World</Button>
</Grid>
</Window>
btnHelloWorld is the Id/Name of the button and btnHelloWorld_Click is the name event Click .Also, add this code to the code behind (Window1.xaml.cs)
private void btnHelloWorld_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("From Code.GigyOnline website");
}
And we are ready to launch our application.
When you compile a WPF application in Visual Studio it will compile your XAML files into a compressed representation known as Binary Application Markup Language (BAML). The BAML is then saved as a resource in the resultant assembly. When that assembly is loaded and the resource is requested, the BAML is streamed out and very quickly turned into the object graph described by the original XAML.
<Window x:Class="WPFHelloWorld.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Hello World from WPF" Height="300" Width="300">
<Grid>
<Button Name ="btnHelloWorld" Content="Hello World"
Click="btnHelloWorld_Click"
Height="60"
Margin="61,0"
VerticalAlignment="Top">
<Button.Background>
<LinearGradientBrush>
<GradientStop Color="Yellow" Offset="0"/>
<GradientStop Color="Green" Offset="1" />
</LinearGradientBrush>
</Button.Background>
</Button>
</Grid>
</Window>
|
|
