Presentation is loading. Please wait.

Presentation is loading. Please wait.

Windows Presentation Foundation. Agenda Introduction Developing Applications WPF and WF interoperability Custom Controls Styles and Templates Data Binding.

Similar presentations


Presentation on theme: "Windows Presentation Foundation. Agenda Introduction Developing Applications WPF and WF interoperability Custom Controls Styles and Templates Data Binding."— Presentation transcript:

1 Windows Presentation Foundation

2 Agenda Introduction Developing Applications WPF and WF interoperability Custom Controls Styles and Templates Data Binding Graphics Not covered sections Resume

3 Introduction

4 Progress WinAPI MFC Windows Forms WPF

5 WPF Components

6 Main features New GUI core Declarative programming using XAML Layout system Styles Control Templates Data Templates Flexible Data Binding Graphics and Multimedia support Improved security model Unified document format (XML Paper Specification) Compatibility with Windows Forms

7 Developing Applications

8 Developer Environment Visual Studio 2005.NET 3.0 Visual Studio Extensions Windows SDK

9 Application types XAML browser applications Stand-alone applications –Windows Applications –Hosted in WPF Navigation Window

10 XAML browser application WPF Everywhere for XAML + browser plug-in Installed using ClickOnce Run in browser Internet Zone security

11 Stand-alone application User permissions Like a standard Windows Application

12 Creating stand-alone application Create WPF project –Windows Application (WPF) –Custom Control Library (WPF) Create class –User Control (WPF) –Custom Control (WPF) –Window (WPF) Create styles and templates –Resource dictionary –Local resource

13 Kinds of WPF Project objects User control –CS code-behind file –XAML declaration Custom control –CS implementation –Style in XAML resource dictionary XAML Resource –Style or Data Template or Control Template in XAML resource dictionary

14 WPF Application Project structure Application class (User control) –Based on System.Windows.Application –Build action – ApplicationDefinition –StartupUri property in XAML – Window class Window class (User control) –Based on System.Windows.Window User Control class (User control) –Based on System.Windows.Controls.UserControl Custom Control class (Custom control) –Based on System.Windows.Controls.Control –Overrides metadata in static constructor Resource Dictionary (XAML Resource) –Top file tag ResourceDictionary –Main file “themes\generic.xaml”

15 WPF Application Project screen shot

16 WPF and WF interoperability

17 WPF and WF interoperability Agenda Hosting a Windows Form Control in WPF Hosting a WPF Control in Windows Forms Troubleshooting Hybrid Applications

18 Hosting a WF Control in WPF 1.Create Windows Application (WPF) project 2.Add reference to the WindowsFormsIntegration assembly 3.Add reference to the System.Windows.Forms assembly 4.Create System.Windows.Forms.Integration. WindowsFormsHost host object 5.Set WF control to Child property of host object 6.Add host object onto WPF panel (for example, Window)

19 Hosting a WF Control in WPF - sample // Creating Windows Form control MaskedTextBox mtbDate = new MaskedTextBox("00/00/0000"); // Creating Integration host WindowsFormsHost host = new WindowsFormsHost(); host.Child = mtbDate; // Appending host to Window this.AddChild(host);

20 Hosting a WPF Control in WF 1.Create Windows Application (WinForms) project 2.Add references to WindowsFormsIntegration, PresentationCore, PresentationFramework and WindowsBase assemblies 3.Add into project file the following line : Just after 5.Create System.Windows.Forms.Integration.ElementHost host object 6.Add WPF control to host object 7.Add host object on WF Form

21 Hosting a WPF Control in WF // Create WPF Control TextBlock textBlock = new TextBlock(); textBlock.Text = "WPF TextBlock control"; // Create host ElementHost host = new ElementHost(); host.Child = textBlock; host.Dock = DockStyle.Fill; // Add host to Form this.Controls.Add(host);

22 Troubleshooting Hybrid Applications Overlapping Controls Child Property Scaling Adapter Nesting Focus Property Mapping Layout-related Properties on Hosted Content Navigation Applications Opacity and Layering Dispose Enabling Visual Styles Licensed Controls

23 Custom Controls

24 Models for Control Authoring Restyle existed controls Derive from UserControl Derive from Control Derive from FrameworkElement

25 Restyle existed controls Simplest way No additional properties Custom control logic only in XAML

26 Restyle existed controls – example

27 Restyle existed controls – screen shot

28 Derive from UserControl Built like Application Composite of existed controls No complex customization

29 Deriving from UserControl - example <TextBlock Text="{Binding ElementName=parent,Path=LabelText}" Margin="5"/> <TextBox Text="{Binding ElementName=parent,Path=ValueText}" Margin="5"/>

30 Deriving from UserControl – example <Window x:Class="UserControls.Window" xmlns:l="clr-namespace:UserControls"> <l:UserControl LabelText="Label Text“ ValueText="Value Text"/>

31 Deriving from UserControl – screen shot

32 Deriving from Control Flexible way Like most WPF controls Support Control Templates Support Themes

33 Deriving from Control - example

34 Deriving from FrameworkElement Own Render way Appearance is defined by own render logic

35 Styles and Templates

36 Styling and Templating Resources Style structure Data Templates Control Templates Triggers

37 Styling and Templating - Resources Store local Styles, Data Templates and Control Templates Apply to FrameworkElement and FrameworkContentElement Share resources via Resource Dictionaries Static and Dynamic resources

38 Resources example <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:ControlLibrary">

39 Styling and Templating – Style structure Naming and Referencing Deriving Styles Setters Data Template Control Template Triggers

40 Styling and Templating – Data Templates Name and Data Type Visual data content Content Control and Content Presenter Triggers

41 Styling and Templating – Control Templates Name and Target Type Visual data content Template Attributes Triggers

42 Styling and Templating – Triggers Trigger and Multi Trigger Data Trigger and Multi Data Trigger Event Trigger and Multi Event Trigger

43 Data Binding

44 Binding a dependency property to a CLR property Path == DaraSource Binding only to dependency properties

45 Data Context 1.The binding looks for a non-null DataContext on the TextBox itself 2.The binding looks for a non-null DataContext on the Grid 3.The binding looks for a non-null DataContext on the Window

46 Master-Detail Binding public class Families : ObservableCollection { } public class Family { string familyName; public string FamilyName { get { return familyName; } set { familyName = value; } } People members; public People Members { get { return members; } set { members = value; } } public class People : ObservableCollection { } public class Person { string name; public string Name { get { return name; } set { name = value; } } int age; public int Age { get { return age; } set { age = value; } }

47 Master-Detail Binding <?Mapping XmlNamespace="local" ClrNamespace="MasterDetailBinding" ?>...

48 Master-Detail Binding...... Families: <ListBox Grid.Row="1" Grid.Column="0" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}">

49 Graphics

50 Not covered sections

51 Sections Security model Web Browser Applications Using multimedia and graphics Easy to restyle application

52 Resume

53 Advantages WPF has very flexible model XAML is a great advance in declarative programming Easy to use multimedia and graphics Easy to restyle application

54 Disadvantages WPF functionality is not so high as WF one WPF and WF interoperability is buggy VS support of XAML is buggy and not full Most available WPF documentation is out of date


Download ppt "Windows Presentation Foundation. Agenda Introduction Developing Applications WPF and WF interoperability Custom Controls Styles and Templates Data Binding."

Similar presentations


Ads by Google