Wednesday, October 22, 2008

WPF And XAML

Windows Presentation Foundation (WPF) is the code-name of the presentation (user-interfaces) sub system in Windows Vista programming model and is used to create user interfaces. This blog talks about WPF.
What is WPF?
WPF is the engine that is responsible for creating, displaying, and manipulating user-interfaces, documents, images, movies, and media in Windows Vista.
Physically, WPF is a set of libraries that have all functionalty you need to build, run, execute, and manage Windows Vista applications.
What is XAML?
XAML is a new descriptive programming language developed by Microsoft to write user interfaces for next generation managed applications.
How XAML is related to WPF?
XAML is a new descriptive programming language developed by Microsoft to write user interfaces for next generation managed applications. XAML is used in WPF to represent the controls and code with the help of C#, Visual Basic, and other .NET Framework languages.

XAML can be think as ASP.NET and/or Windows Forms in Windows Vista. For example, to write a Web application in .NET 1.0, 1.1, or 2.0, you use ASP.NET and to write Windows Applications, you use Windows Forms. Now in Windows Vista and .NET 3.0, you will use XAML instead of Windows Forms and ASP.NET.

Does that mean XAML will replace ASP.NET and Windows Forms? YES and NO. Both ASP.NET and Windows Forms will also be supported on .NET 3.0 but you don't have to use them if you don't want.
What Operating Systems does WPF support?
Windows Vista, Windows XP, and Windows 2003 Server.
How do I build WPF Applicaitons?
To build WPF application, you must install .NET 3.0 SDK. It can be found on MSDN downloads sites.
What do I need to run WPF Applications?
To run WPF applications, you must install .NET 3.0 SDK redistributable. It can be found on MSDN downloads sites.

WCF Contracts

The WCF way to generate an XML schema from a CLR type is with a data contract. Data contracts describe how a CLR type maps to schema with an opt-in approach. The XmlFormatter uses the information provided in a data contract to handle serialization and deserialization. This allows developers to work with familiar objects at runtime, while the WCF runtime hides the XML goo. The XmlFormatter is the successor of the XmlSerializer for WCF services - with the exception that currently, the XmlSerializer still provides more granular control over object serialization to XML. As such there will still be cases where you will still want to use the XmlSerializer, for now.
Creating a Data Contract
First you decorate the type with the DataContractAttribute, then you select members to include in serialization with the DataMemberAttribute. Listing 3 illustrates the LinkItem type mentioned earlier, as a data contract.


Service Contracts
In the WCF, service contracts describe the operations supported by a service, the message exchange pattern they use, and the format of each message. The service contract is the driver for generating a service description – so a service must implement at least one service contract. To create a service contract you define an interface with related methods representative of a collection of service operations, and then decorate the interface with the ServiceContractAttribute to indicate it is a service contract. Methods in the interface that should be included in the service contract are decorated with the OperationContractAttribute. Listing 1 illustrates the use of these attributes