Sunteți pe pagina 1din 14

XAML and WPF

Extensible Application Markup


Language
• XAML is a declarative markup language typically used to
create an application's user interface.
• It got its start in 2006 when Windows Presentation
Foundation (WPF) was introduced as part of
the .NETFramework 3.0.
• Positioned as the follow-up to Windows Forms, it's no
wonder adoption was slow.
WPF advantages
1. It's newer and thereby more in tune with current standards
2. Microsoft is using it for a lot of new applications, e.g. Visual Studio
3. It's more flexible, so you can do more things without having to write or buy new
controls
4. When you do need to use 3rd party controls, the developers of these controls
will likely be more focused on WPF because it's newer
5. XAML makes it easy to create and edit your GUI, and allows the work to be
split between a designer (XAML) and a programmer (C#, VB.NET etc.)
6. Databinding, which allows you to get a more clean separation of data and
layout
7. Uses hardware acceleration for drawing the GUI, for better performance
8. It allows you to make user interfaces for both Windows applications and web
applications (Silverlight/XBAP)
WinForms advantages

1. It's older and thereby more tried and tested

2. There are already a lot of 3rd party controls that you can buy or get for free

3. The designer in Visual Studio is still, as of writing, better for WinForms


than for WPF, where you will have to do more of the work yourself with
WPF
XAML
• XAML - Extensible Application Markup Language.
• It’s a simple and declarative language based on XML.
• In XAML, it very easy to create, initialize, and set
properties of an object with hierarchical relations.
• It is mainly used for designing GUIs.
• It can be used for other purposes as well, e.g., to declare
workflow in Workflow Foundation.
• XAML can be used in different platforms such as WPF (Windows
Presentation Foundation), Silverlight, Mobile Development, and
Windows Store App.
• It can be used across different .Net framework and CLR (common
language runtime) versions.
• XAML is a declarative markup language. As applied to
the .NET Framework programming model, XAML
simplifies creating a UI for a .NET Framework
application.
• You can create visible UI elements in the declarative
XAML markup, and then separate the UI definition from
the run-time logic by using code-behind files, joined to the
markup through partial class definitions.
• When represented as text, XAML files are XML files that
generally have the .xaml extension.
• The files can be encoded by any XML encoding, but
encoding as UTF-8 is typical.
<StackPanel>
<Button Content="Click Me"/>
</StackPanel>
A WPF Application
• our primary focus will be on using WPF to create applications.
• As you may know, .NET can be executed on all platforms which have
a .NET implementation, but the most common platform is still
Microsoft Windows.
• When we talk about Windows applications, it really just means an
application that runs on Windows (or another .NET compatible platform)
and not in a browser or remotely over the Internet.
A WPF Application
• A WPF application requires the .NET framework to run, just like any other
.NET application type

• Fortunately, Microsoft has been including the .NET framework on all


versions of Windows since Vista, and they have been pushing out the
framework on older versions through Windows Update. In other words, you
can be pretty sure that most Windows users out there will be able to run
your WPF application.
The Window
• When creating a WPF application, the first thing you will meet is the
Window class.
• It serves as the root of a window and provides you with the standard
border, title bar and maximize, minimize and close buttons.
• A WPF window is a combination of a XAML (.xaml) file, where the
<Window> element is the root, and a CodeBehind (.cs) file.
• If you're using Visual Studio (Express) and you create a new WPF
application, it will create a default window for you, which will look
something like this:
<Window x:Class="WpfApplication1.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>

</Grid>
</Window>
Hello wpf

S-ar putea să vă placă și