Windows Presentation Foundation Introduction To Windows .

2y ago
20 Views
2 Downloads
1.40 MB
41 Pages
Last View : 3m ago
Last Download : 3m ago
Upload by : Fiona Harless
Transcription

Introduction to Windows Presentation FoundationPage 1 of 41 2009 Microsoft Corporation. All rights reserved.Windows Presentation FoundationIntroduction to Windows Presentation FoundationWindows Presentation Foundation (WPF) is a next-generation presentation system for building Windows clientapplications with visually stunning user experiences. With WPF, you can create a wide range of both standalone andbrowser-hosted applications. Some examples are Yahoo! Messenger [ http://go.microsoft.com/fwlink/?LinkId 91192 ] and the New York Times Reader [ http://go.microsoft.com/fwlink/?LinkId 91193 ] , as well as theContoso Healthcare Sample Application [ http://go.microsoft.com/fwlink/?LinkId 91196 ] that is shown in thefollowing figure.The core of WPF is a resolution-independent and vector-based rendering engine that is built to take advantage ofmodern graphics hardware. WPF extends the core with a comprehensive set of application-development features thatinclude Extensible Application Markup Language (XAML), controls, data binding, layout, 2-D and 3-D graphics,animation, styles, templates, documents, media, text, and typography. WPF is included in the Microsoft .NETFramework, so you can build applications that incorporate other elements of the .NET Framework class library.This overview is intended for newcomers and covers the key capabilities and concepts of WPF. Experienced WPFdevelopers seeking a review of WPF may also find this overview useful.Note:For new and updated WPF features in the .NET Framework 3.5, see What's New in Windows PresentationFoundation Version 3.5 [ spx ] .This topic contains the following sections. Programming with WPFMarkup and 9

Introduction to Windows Presentation Foundation Page 2 of 41Input and CommandingLayoutData BindingGraphicsAnimationMediaText and TypographyDocumentsCustomizing WPF ApplicationsWPF Best PracticesSummaryRecommended Overviews and SamplesRelated TopicsProgramming with WPFWPF exists as a subset of .NET Framework types that are for the most part located in the System.Windows[ dows.aspx ] namespace. If you have previously builtapplications with .NET Framework using managed technologies like ASP.NET and Windows Forms, the fundamentalWPF programming experience should be familiar; you instantiate classes, set properties, call methods, and handleevents, all using your favorite .NET Framework programming language, such as C# or Visual Basic.To support some of the more powerful WPF capabilities and to simplify the programming experience, WPF includesadditional programming constructs that enhance properties and events: dependency properties and routedevents. For more information on dependency properties, see Dependency Properties Overview[ spx ] . For more information on routed events, see RoutedEvents Overview [ spx ] .Markup and Code-BehindWPF offers additional programming enhancements for Windows client application development. One obviousenhancement is the ability to develop an application using both markup and code-behind, an experience thatASP.NET developers should be familiar with. You generally use Extensible Application Markup Language(XAML) markup to implement the appearance of an application while using managed programming languages (codebehind) to implement its behavior. This separation of appearance and behavior has the following benefits: Development and maintenance costs are reduced because appearance-specific markup is not tightlycoupled with behavior-specific code. Development is more efficient because designers can implement an application's appearancesimultaneously with developers who are implementing the application's behavior. Multiple design tools can be used to implement and share XAML markup, to target the requirements ofthe application development contributors; Microsoft Expression Blend[ http://go.microsoft.com/fwlink.aspx?LinkID 88924 ] provides an experience that suits designers,while Visual Studio 2005 targets developers. Globalization and localization for WPF applications is greatly simplified (see WPF Globalization andLocalization Overview [ spx ] ).The following is a brief introduction to WPF markup and code-behind. For more information on this programmingmodel, see XAML Overview [ spx ] and Code-Behind andXAML [ spx ] .MarkupXAML is an XML-based markup language that is used to implement an application's appearance declaratively. It istypically used to create windows, dialog boxes, pages, and user controls, and to fill them with controls, shapes, andgraphics.The following example uses XAML to implement the appearance of a window that contains a single button.XAMLCopy Code Windowxmlns a970268(printer).aspx8/5/2009

Introduction to Windows Presentation FoundationPage 3 of 41Title "Window with Button"Width "250" Height "100" !-- Add button to window -- Button Name "button" Click Me! /Button /Window Specifically, this XAML defines a window and a button by using the Window and Button elements, respectively. Eachelement is configured with attributes, such as the Window element's Title attribute to specify the window's title-bartext. At run time, WPF converts the elements and attributes that are defined in markup to instances of WPF classes.For example, the Window element is converted to an instance of the Window [ ows.window.aspx ] class whose Title [ ows.window.title.aspx ] property is the value of the Title attribute.The following figure shows the user interface (UI) that is defined by the XAML in the previous example.For more information, see XAML Overview [ spx ] .Since XAML is XML-based, the UI that you compose with it is assembled in a hierarchy of nested elements known asan element tree. The element tree provides a logical and intuitive way to create and manage UIs. For moreinformation, see Trees in WPF [ spx ] .Code-BehindThe main behavior of an application is to implement the functionality that responds to user interactions, includinghandling events (for example, clicking a menu, tool bar, or button) and calling business logic and data access logicin response. In WPF, this behavior is generally implemented in code that is associated with markup. This type ofcode is known as code-behind. The following example shows the code-behind and updated markup from theprevious example.XAMLCopy Code Windowxmlns entation"xmlns:x ass "SDKSample.AWindow"Title "Window with Button"Width "250" Height "100" !-- Add button to window -- Button Name "button" Click "button Click" Click Me! /Button /Window Visual BasicCopy CodeNamespace SDKSamplePartial Public Class AWindowInherits System.Windows.WindowPublic Sub New()' InitializeComponent call is required to merge the UI' that is defined in markup with this class, including' setting properties and registering event handlersInitializeComponent()End 8(printer).aspx8/5/2009

Introduction to Windows Presentation FoundationPage 4 of 41Private Sub button Click(ByVal sender As Object, ByVal e As RoutedEventArgs)' Show message box when button is clickedMessageBox.Show("Hello, Windows Presentation Foundation!")End SubEnd ClassEnd NamespaceC#Copy Codeusing System.Windows; // Window, RoutedEventArgs, MessageBoxnamespace SDKSample{public partial class AWindow : Window{public AWindow(){// InitializeComponent call is required to merge the UI// that is defined in markup with this class, including// setting properties and registering event handlersInitializeComponent();}void button Click(object sender, RoutedEventArgs e){// Show message box when button is clickedMessageBox.Show("Hello, Windows Presentation Foundation!");}}}In this example, the code-behind implements a class that derives from the Window [ ows.window.aspx ] class. The x:Class attribute is used to associate the markup with the code-behind class. InitializeComponent is called from the code-behind class's constructor to merge the UI that is definedin markup with the code-behind class. (InitializeComponent is generated for you when your application is built,which is why you don't need to implement it manually.) The combination of x:Class and InitializeComponent ensurethat your implementation is correctly initialized whenever it is created. The code-behind class also implements anevent handler for the button's Click [ ows.controls.primitives.buttonbase.click.aspx ] event. When the button is clicked, the eventhandler shows a message box by calling the MessageBox.Show [ ows.messagebox.show.aspx ] method.The following figure shows the result when the button is clicked.For more information, see Code-Behind and XAML [ spx ] ry/aa970268(printer).aspx8/5/2009

Introduction to Windows Presentation FoundationPage 5 of 41.NET Framework, System.Windows [ dows.aspx ] , and markupand code-behind, constitute the foundation of the WPF application development experience. Additionally, WPF hascomprehensive features for creating user experiences with rich content. To package this content and deliver it tousers as "applications," WPF provides types and services that are collectively known as the application model. Theapplication model supports the development of both standalone and browser-hosted applications.Standalone ApplicationsFor standalone applications, you can use the Window [ ows.window.aspx ] class to create windows and dialog boxes that are accessed from menubars and tool bars. The following figure shows a standalone application with a main window and a dialog box.Additionally, you can use the following WPF dialog boxes: MessageBox [ ows.messagebox.aspx ] , OpenFileDialog [ in32.openfiledialog.aspx ] , SaveFileDialog [ in32.savefiledialog.aspx ] , and PrintDialog [ ows.controls.printdialog.aspx ] .For more information, see WPF Windows Overview [ spx ] .Browser-Hosted ApplicationsFor browser-hosted applications, known as XAML browser applications (XBAPs), you can create pages ( Page[ dows.controls.page.aspx ] ) and page functions(PageFunction(T) [ spx ] ) that you can navigate betweenusing hyperlinks ( Hyperlink [ ows.documents.hyperlink.aspx ] classes). The following figure shows a page in an XBAP thatis hosted in Internet Explorer (printer).aspx8/5/2009

Introduction to Windows Presentation FoundationPage 6 of 41WPF applications can be hosted in both Microsoft Internet Explorer 6 and Internet Explorer 7. WPF offers the twofollowing options for alternative navigation hosts: Frame [ dows.controls.frame.aspx ] , to hostislands of navigable content in either pages or windows. NavigationWindow [ ows.navigation.navigationwindow.aspx ] , to host navigable content in an entirewindow.For more information, see Navigation Overview [ spx ] .The Application ClassBoth XBAPs and standalone applications are often complex enough to require additional application-scoped services,including startup and lifetime management, shared properties, and shared resources. The Application[ dows.application.aspx ] class encapsulates these services andmore, and it can be implemented by just using XAML, as shown in the following y/aa970268(printer).aspxCopy Code8/5/2009

Introduction to Windows Presentation FoundationPage 7 of 41 Applicationxmlns entation"StartupUri "MainWindow.xaml" / This markup is the application definition for a standalone application, and instructs WPF to create an Application[ dows.application.aspx ] object that automatically opensMainWindow [ dows.application.mainwindow.aspx ] when theapplication is started.A key concept to understand about Application [ ows.application.aspx ] is that it provides a common platform of support for both standaloneand browser-hosted applications. For example, the preceding XAML could be used by a browser-hosted applicationto automatically navigate to a page when an XBAP is started, as shown in the following example.XAMLCopy Code Applicationxmlns entation"StartupUri "HomePage.xaml" / For more information, see Application Management Overview [ px ] .SecurityBecause XBAPs are hosted in a browser, security is important. In particular, a partial-trust security sandbox is usedby XBAPs to enforce restrictions that are less than or equal to the restrictions imposed on HTML-based applications.Furthermore, each HTML feature that is safe to run from XBAPs in partial trust has been tested using acomprehensive security process, detailed in Windows Presentation Foundation Security Strategy - SecurityEngineering [ spx ] .Still, a majority of WPF features can be safely executed from XBAPs, as described in Windows PresentationFoundation Partial Trust Security [ spx ] .ControlsThe user experiences that are delivered by the application model are constructed controls. In WPF, "control" is anumbrella term that applies to a category of WPF classes that are hosted in either a window or a page, have a userinterface (UI), and implement some behavior.For more information, see Controls Overview [ spx ] . Forintroductory samples, see Control Library Samples [ spx ]WPF Control Roll CallThe built-in WPF controls are listed here. Buttons: Button [ dows.controls.button.aspx ]and RepeatButton [ ows.controls.primitives.repeatbutton.aspx ] . Dialog Boxes: OpenFileDialog [ in32.openfiledialog.aspx ] , PrintDialog [ ows.controls.printdialog.aspx ] , and SaveFileDialog[ win32.savefiledialog.aspx ] . Digital Ink: InkCanvas [ ows.controls.inkcanvas.aspx ] and InkPresenter [ ows.controls.inkpresenter.aspx ] . Documents: DocumentViewer [ ows.controls.documentviewer.aspx ] , FlowDocumentPageViewer[ dows.controls.flowdocumentpageviewer.aspx ] printer).aspx8/5/2009

Introduction to Windows Presentation FoundationPage 8 of 41FlowDocumentReader [ ows.controls.flowdocumentreader.aspx ] , FlowDocumentScrollViewer[ dows.controls.flowdocumentscrollviewer.aspx ] ,and StickyNoteControl [ ows.controls.stickynotecontrol.aspx ] . Input: TextBox [ dows.controls.textbox.aspx ] ,RichTextBox [ dows.controls.richtextbox.aspx ] ,and PasswordBox [ ows.controls.passwordbox.aspx ] . Layout: Border [ dows.controls.border.aspx ] ,BulletDecorator [ ows.controls.primitives.bulletdecorator.aspx ] , Canvas[ dows.controls.canvas.aspx ] , DockPanel[ dows.controls.dockpanel.aspx ] , Expander[ dows.controls.expander.aspx ] , Grid[ dows.controls.grid.aspx ] , GridView[ dows.controls.gridview.aspx ] , GridSplitter[ dows.controls.gridsplitter.aspx ] , GroupBox[ dows.controls.groupbox.aspx ] , Panel[ dows.controls.panel.aspx ] , ResizeGrip[ dows.controls.primitives.resizegrip.aspx ] ,Separator [ dows.controls.separator.aspx ] ,ScrollBar [ ows.controls.primitives.scrollbar.aspx ] , ScrollViewer[ dows.controls.scrollviewer.aspx ] , StackPanel[ dows.controls.stackpanel.aspx ] , Thumb[ dows.controls.primitives.thumb.aspx ] , Viewbox[ dows.controls.viewbox.aspx ] ,VirtualizingStackPanel [ ows.controls.virtualizingstackpanel.aspx ] , Window[ dows.window.aspx ] , and WrapPanel[ dows.controls.wrappanel.aspx ] . Media: Image [ dows.controls.image.aspx ] ,MediaElement [ ows.controls.mediaelement.aspx ] , and SoundPlayerAction[ dows.controls.soundplayeraction.aspx ] . Menus: ContextMenu [ ows.controls.contextmenu.aspx ] , Menu [ ows.controls.menu.aspx ] , and ToolBar [ ows.controls.toolbar.aspx ] . Navigation: Frame [ dows.controls.frame.aspx ] ,Hyperlink [ dows.documents.hyperlink.aspx ] ,Page [ dows.controls.page.aspx ] ,NavigationWindow [ ows.navigation.navigationwindow.aspx ] , and TabControl[ dows.controls.tabcontrol.aspx ] . Selection: CheckBox [ ows.controls.checkbox.aspx ] , ComboBox [ ows.controls.combobox.aspx ] , ListBox [ ows.controls.listbox.aspx ] , TreeView [ ows.controls.treeview.aspx ] , and RadioButton [ ows.controls.radiobutton.aspx ] , Slider [ ows.controls.slider.aspx ] . User Information: AccessText [ ows.controls.accesstext.aspx ] , Label [ .com/en-us/library/aa970268(printer).aspx8/5/2009

Introduction to Windows Presentation FoundationPage 9 of 41us/library/system.windows.controls.label.aspx ] , Popup [ ows.controls.primitives.popup.aspx ] , ProgressBar[ dows.controls.progressbar.aspx ] , StatusBar[ dows.controls.primitives.statusbar.aspx ] ,TextBlock [ dows.controls.textblock.aspx ] , andToolTip [ dows.controls.tooltip.aspx ] .Input and CommandingControls most often detect and respond to user input. The WPF input system uses both direct and routed eventsto support text input, focus management, and mouse positioning. For more information, see Input Overview[ spx ] .Applications often have complex input requirements. WPF provides a command system that separates user inputactions from the code that responds to those actions. For more information, see Commanding Overview[ spx ] .LayoutWhen you create a UI, you arrange your controls by location and size to form a layout. A key requirement of anylayout is to adapt to changes in window size and display settings. Rather than forcing you to write the code to adapta layout in these circumstances, WPF provides a first-class, extensible layout system for you.The cornerstone of the layout system is relative positioning, which increases the ability to adapt to changing windowand display conditions. In addition, the layout system manages the negotiation between controls to determine thelayout. The negotiation is a two-step process: first, a control tells its parent what location and size it requires;second, the parent tells the control what space it can have.The layout system is exposed to child controls through base WPF classes. For common layouts such as grids,stacking, and docking, WPF includes several layout controls: Canvas [ dows.controls.canvas.aspx ] : Childcontrols provide their own layout. DockPanel [ dows.controls.dockpanel.aspx ] : Childcontrols are aligned to the edges of the panel. Grid [ dows.controls.grid.aspx ] : Child controlsare positioned by rows and columns. StackPanel [ dows.controls.stackpanel.aspx ] :Child controls are stacked either vertically or horizontally. VirtualizingStackPanel [ ows.controls.virtualizingstackpanel.aspx ] : Child controls are virtualized andarranged on a single line that is either horizontally or vertically oriented. WrapPanel [ dows.controls.wrappanel.aspx ] :Child controls are positioned in left-to-right order and wrapped to the next line when there are morecontrols on the current line than space allows.The following example uses a DockPanel [ ows.controls.dockpanel.aspx ] to lay out several TextBox [ ows.controls.textbox.aspx ] controls.XAMLCopy Code Windowxmlns entation"xmlns:x ass "SDKSample.LayoutWindow"Title "Layout with the DockPanel" Height "143" Width "319" !--DockPanel to layout four text boxes-- DockPanel TextBox DockPanel.Dock "Top" Dock "Top" /TextBox rinter).aspx8/5/2009

Introduction to Windows Presentation FoundationPage 10 of 41 TextBox DockPanel.Dock "Bottom" Dock "Bottom" /TextBox TextBox DockPanel.Dock "Left" Dock "Left" /TextBox TextBox Background "White" This TextBox "fills" the remaining space. /TextBox /DockPanel /Window The DockPanel [ dows.controls.dockpanel.aspx ] allows thechild TextBox [ dows.controls.textbox.aspx ] controls to tell ithow to arrange them. To do this, the DockPanel [ ows.controls.dockpanel.aspx ] implements a Dock [ ows.controls.dockpanel.dock.aspx ] property that is exposed to the child controls to alloweach of them to specify a dock style.Note:A property that is implemented by a parent control for use by child controls is a WPF construct called anattached property (see Attached Properties Overview [ px ] ).The following figure shows the result of the XAML markup in the preceding example.For more information, see The Layout System [ spx ] . For anintroductory sample, see WPF Layout Gallery Sample [ spx ] .Data BindingMost applications are created to provide users with the means to view and edit data. For WPF applications, the workof storing and accessing data is already provided for by technologies such as Microsoft SQL Server and ADO.NET.After the data is accessed and loaded into an application's managed objects, the hard work for WPF applicationsbegins. Essentially, this involves two things:1. Copying the data from the managed objects into controls, where the data can be displayed and edited.2. Ensuring that changes made to data by using controls are copied back to the managed objects.To simplify application development, WPF provides a data binding engine to automatically perform these steps. Thecore unit of the data binding engine is the Binding [ ows.data.binding.aspx ] class, whose job is to bind a control (the binding target) to a dataobject (the binding source). This relationship is illustrated by the following figure.The following example demonstrates how to bind a TextBox [ ows.controls.textbox.aspx ] to an instance of a custom Person object. The Personimplementation is shown in the following 268(printer).aspx8/5/2009

Introduction to Windows Presentation FoundationVisual BasicPage 11 of 41Copy CodeNamespace SDKSampleClass PersonPrivate name As String "No Name"Public Property Name() As StringGetReturn nameEnd GetSet(ByVal value As String)name valueEnd SetEnd PropertyEnd ClassEnd NamespaceC#Copy Codenamespace SDKSample{class Person{string name "No Name";public string Name{get { return name; }set { name value; }}}}The following markup binds the TextBox [ ows.controls.textbox.aspx ] to an instance of a custom Person object.XAMLCopy Code Windowxmlns entation"xmlns:x ass "SDKSample.DataBindingWindow" . !-- Bind the TextBox to the data source (TextBox.Text to Person.Name) -- TextBox Name "personNameTextBox" Text "{Binding Path Name}" / . /Window Visual BasicCopy CodeImports System.Windows ' WindowNamespace SDKSamplePartial Public Class ibrary/aa970268(printer).aspx8/5/2009

Introduction to Windows Presentation FoundationPage 12 of 41Inherits WindowPublic Sub New()InitializeComponent()' Create Person data sourceDim person As Person New Person()' Make data source available for bindingMe.DataContext personEnd SubEnd ClassEnd NamespaceC#Copy Codeusing System.Windows; // Windownamespace SDKSample{public partial class DataBindingWindow : Window{public DataBindingWindow(){InitializeComponent();// Create Person data sourcePerson person new Person();// Make data source available for bindingthis.DataContext person;}}}In this example, the Person class is instantiated in code-behind and is set as the data context for theDataBindingWindow. In markup, the Text [ ows.controls.textbox.text.aspx ] property of the TextBox [ ows.controls.textbox.aspx ] is bound to the Person.Name property (using the"{Binding . }" XAML syntax). This XAML tells WPF to bind the TextBox [ ows.controls.textbox.aspx ] control to the Person object that is stored in the DataContext[ dows.frameworkelement.datacontext.aspx ] property of thewindow.The WPF data binding engine provides additional support that includes validation, sorting, filtering, and grouping.Furthermore, data binding supports the use of data templates to create custom UI for bound data when the UIdisplayed by the standard WPF controls is not appropriate.For more information, see Data Binding

Aug 05, 2009 · Windows Presentation Foundation Introduction to Windows Presentation Foundation Windows Presentation Foundation (WPF) is a next-generation presentation system for building Windows client applications with visually stunning user experiences. With WPF, you can create a wide range of both standalone and browser-hosted applications. Some examples .

Related Documents:

The Windows The Windows Universe Universe Windows 3.1 Windows for Workgroups Windows 95 Windows 98 Windows 2000 1990 Today Business Consumer Windows Me Windows NT 3.51 Windows NT 4 Windows XP Pro/Home. 8 Windows XP Flavors Windows XP Professional Windows XP Home Windows 2003 Server

AutoCAD 2000 HDI 1.x.x Windows 95, 98, Me Windows NT4 Windows 2000 AutoCAD 2000i HDI 2.x.x Windows 95, 98, Me Windows NT4 Windows 2000 AutoCAD 2002 HDI 3.x.x Windows 98, Me Windows NT4 Windows 2000 Windows XP (with Autodesk update) AutoCAD 2004 HDI 4.x.x Windows NT4 Windows 2000 Windows XP AutoCAD 2005 HDI 5.x.x Windows 2000 Windows XP

3. What is Windows Workflow Foundation Windows Workflow Foundation (WF) is part of the .NET framework for .NET developers. Introduced with version 3.0 of the .NET platform, Microsoft combines WF (Windows Workflow Foundation), WCF (Windows Communication Foundation) and WPF (Windows Presentation Foundation) along

A computer with at least a 450MHz Pentium CPU with 128 MB of RAM, running Windows 2000, Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7, Windows 8/8.1, Windows 10, Windows Server 2012, Windows Server 2016 or Windows Server 2019 platforms. Instal

Intro - Windows Presentation Foundation Introduced in .Net 3.0 alongside: . Communication Foundation (WCF) SOAP / Web services . Workflow Foundation (WWF) Workflow Engine / Activities . Presentation Foundation (WPF) GUI framework Released in Nov '06 Pre-installed on Windows Vista

Windows 8.1 *6 Windows Server 2003 *7 Windows Server 2008 *8 Windows Server 2012 *9 Mac OS X *10: Supported *1 Printer drivers support both 32-bit and 64-bit Windows. *2 Microsoft Windows XP Professional Edition/Microsoft Windows XP Home Edition *3 Microsoft Windows Vista Ultimate/Microsoft Windows Vista Enterprise/Microsoft Windows Vista Business/

Microsoft Windows Server 2008 R2 SP1 Standard Edition Microsoft Windows Server 2008 R2 SP1 Datacenter Edition Microsoft Windows Server 2012 Family SAS 9.4 Foundation is supported on the following editions of the Windows Server 2012 family with SAS 9.4 TS1M1 and higher: Microsoft Windows Server 2012 Foundation Edition Microsoft Windows Server .

API refers to the standard specifications of the American Petroleum Institute. ASME refers to the standard specifications for pressure tank design of the American Society of Mechanical Engineers. WATER TANKS are normally measured in gallons. OIL TANKS are normally measured in barrels of 42 gallons each. STEEL RING CURB is a steel ring used to hold the foundation sand or gravel in place. The .