wpf deep dive

Download WPF Deep Dive

Post on 27-Jun-2015

1.089 views

Category:

Technology

0 download

Embed Size (px)

TRANSCRIPT

WPF Brush-up

WPF Deep DiveAniruddha ChakrabartiSr. Solution ArchitectIf I have six hours to chop down a tree, I will use four hours to sharpen the axe Abraham LincolnKey benefits of WPFBroad integrationProvides access to normal 2D graphics, controls, 3D, video, speech and rich document viewing with consistent programming model as well as tight integrationHardware accelerationImproved Visual RenderingRetained mode graphicsVector graphicsResolution independence (Device Independent Graphics)Declarative programming (aka XAML)Rich composition, layout and customizationEasy deploymentIncorporates best of Web and WindowsIntegrate developers and designersWPF ArchitectureWPF Architecture

WPF: Assemblies and NamespacesPrimary Assemblies containing the WPF APIPresentationFrameworkPresentationCoreWindowsBasemilcore (unmanaged)mil: Media Integration LayerNamespacesSystem.WindowsOther child namespaces starting with System.Windows except System.Windows.Forms (Win Forms)System.Windows.ControlsSystem.Windows.DataSystem.Windows.DocumentsSystem.Windows.Media (+ child namespaces)System.Windows.Shapes

Unmanaged/NativeManagedWPF Base Class Hierarchy

PresentationFrameworkPresentationCoreWindowsBaseWPF Base Class DetailsSystem.Threading.DispatcherObject:Provides basic constructs for dealing with concurrency and threading. WPF is based on a messaging system implemented by the dispatcher - works much like familiar Win32 message pumpSystem.Windows.DependencyObject:Provides reach Property System (DP + attached property)System.Windows.Media.Visual:Provides for building a tree of visual objects. Visual is designed to be extremely lightweight and flexible, so most of the features have no public API exposure.Visual is really the entry point to the WPF composition system. Visual is the point of connection between these two subsystems, the managed API and the unmanaged milcore.System.Windows.UIElement:defines core subsystems including Layout, Input, and EventsSystem.Windows.FrameworkElement:Provides Advanced Layout on top of the features provided by UIElementProvides DataBinding & StylesSystem.Windows.Controls.Control:Provides Templating Support

Different type of WPF applicationsStandalone/Desktop ApplicationsWindow class is used to create windows and dialog boxesBrowser Hosted Applications / XAML Browser Applications (XBAP)Create Page, Page FunctionLoose XAML pages (can be opened in IE)

XAML (eXtensible Application Markup Language)XAML OverviewSimple general-purpose, XML based declarative programming language for constructing & initializing .NET objects.NET Framework 3.0 includes A compiler and run-time parser for XAML, Plug-in that enables to view standalone WPF-based XAML files (sometimes called loose XAML pages) inside IE.Can be used independent of WPF (e.g. WF)XAML Spec defines rules that map .NET namespaces, types, properties, and events into XML namespaces, elements, and attributes.Declaring an XML element in XAML (known as an object element) is equivalent to instantiating the corresponding .NET object (always via a default constructor).Setting an attribute on the object element is equivalent to setting a property of the same name (called a property attribute)XAML Example

Hello World

namespace WpfApplication1{ public partial class Window1 : Window { public Window1() { InitializeComponent(); } }}Window1.xamlWindow1.xaml.csButton btn = new Button();btn.Height = 70;btn.FontFamily = new FontFamily("Verdana");btn.FontSize = 18;btn.Content = "Hello World";

panel.Children.Add(btn);Loose XAML files

Hello from loose XAML page 12XAML NamespaceXAML NamespaceDefault Namespace: declared with xmlns attributeXmlns: http://schemas.microsoft.com/winfx/2006/xaml/presentation - maps to .NET namespace System.Windows.Controls.Mapping defined in PresentationFramework.dll assembly [assembly:XmlnsDefinition (http://schemas.microsoft.com/winfx/2006/xaml/presentation, System.Windows.Controls)]Root object element in a XAML file must specify at least one XML namespace: used to qualify itself & any child elements.Additional XML namespaces (on the root or on children) can be declared , but each one must be given a distinct prefix to be used on any identifiers from that namespace.e.g. WPF XAML files typically use a second namespace with the prefix x (denoted by using xmlns:x instead of just xmlns): xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml (XAML Language namespace) System.Windows.Markup