Introduction to Windows Presentation Foundation (WPF) Dr. Frank McCown COMP 445 – GUI Programming.

Slides:



Advertisements
Similar presentations
Module 1: Creating an Application by Using Windows Presentation Foundation Overview of WPF Creating a Simple WPF Application Handling Events and Commands.
Advertisements

Chapter 3 – Web Design Tables & Page Layout
Panels, Tab Containers Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
RIA User User RIA .net framework Silverlight, WPF.
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Word Lesson 7 Working with Documents
1 Introduction to Word Chapter 3 Lecture Outline.
Dinko Jakovljević Microsoft Student Partner | BambooLab
© by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Painter Application Introducing Graphics with Windows Presentation Foundation.
Windows Presetation Foundation (WPF) 1. Introduction.
1 Moderne GUI og Silverlight Windows Presentation Foundation.
Mahender Sarangam Having close to 5 years of experience. Working as a Senior Software Engineer in United Health Group. Good Knowledge on C#, ASP.NET,
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Computer Literacy BASICS: A Comprehensive Guide to IC 3, 5 th Edition Lesson 15 Working with Tables 1 Morrison / Wells / Ruffolo.
WPF For PowerBuilder Developers
Getting Started with Expression Web 3
.NET Database Technologies: Introduction to WPF and Entity Framework DataBinding.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. WEB.
1 COS240 O-O Languages AUBG, COS dept Lecture 33 Building Apps Technologies C# (WPF part 1)
WPF chapter 15 Dr. John Abraham Professor UTPA. WPF –an introduction WPF provides a single platform capable of handling graphics, audio and video. WPF.
Next Generation for Desktop Applications Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
1 Intro XAML Attribute syntax & property syntax Panels Reusable resources Controls Data binding Steen Jensen, spring 2014.
V 1.1 Programming III. GUI APIs WPF Hello World Important UI elements UI elements / content models UI elements / inheritance.
An Introduction to Silverlight Matt Harrington Developer Evangelist, Microsoft October 20, 2011.
Adding Content to the Agency Web Site - Part 2. Adding individual web pages for success stories Agency Web Site Adding Content 2, Slide 2Copyright © 2004,
C# Events and WPF #W5. Horizontal Prototype WPF Designed for rapid user interface design Used for many devices: Windows Phone, Tablets, PCs,
Windows Presentation Foundation Adam Calderon Principal Engineer Interknowlogy LLC
Domain 3 Understanding the Adobe Dreamweaver CS5 Interface.
Designing a Web Page with Tables. A text table: contains only text, evenly spaced on the Web page in rows and columns uses only standard word processing.
Word 2010 Vocabulary List 1. Click and Type - A feature that allows you to double-click a blank area of a document to position the cursor in that location,
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
LAYOUT CONTROLS. XAML Overview XAML : eXtensible Application Markup Language pronounced (ZAMEL) is a markup language used to design user interfaces XML-based.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
Windows Presentation Foundation (WPF) Chapter 16 Dr. Abraham.
Key Applications Module Lesson 21 — Access Essentials
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
Windows Presentation Foundation Maximilian Knor Developer Evangelist Developer and Plattform Group Microsoft Österreich
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 15 Advanced Tables.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Windows Presentation Foundation (WPF). Introduction Separates appearance of user interface from behavior Appearance usually specified by XAML Behavior.
Rujchai Ung-arunyawee Department of Computer Engineering Khon Kaen University.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
ControlTemplate and DataTemplate Doncho Minkov Telerik School Academy Technical Trainer
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
Positioning Objects with CSS and Tables
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
REC [ ] How to implement CAMERA RECORDING for USB WEBCAM or IP CAMERA in C#.NET SOURCE CODE: ! Welcome to this presentation that explains.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Part of the Microsoft.NET Framework 3.0 Tomer Shamam.NET Technologies Expert Sela Group
Jaime Rodriguez | Microsoft Principal Technical Evangelist Laurent Bugnion | IdentityMine Senior Director XAML Deep Dive for Windows & Windows Phone Apps.
Adam Schultz MVVM and WPF. MVVM Model, View, ViewModel A software architecture designed to separate out User Interface design, Business Logic, and Data.
Introduction to Silverlight
Microsoft Office 2007-Illustrated Introductory, Windows Vista Edition
Windows Presentation Foundation
Windows Presentation Foundation Layout with Panels
Positioning Objects with CSS and Tables
Chapter 2 – Introduction to the Visual Studio .NET IDE
Microsoft Office 2007-Illustrated Introductory, Windows Vista Edition
Introduction to Silverlight
Layouts AKEEL AHMED.
WPF AKEEL AHMED.
.NET and .NET Core 7. XAML Pan Wuming 2017.
Windows Presentation Foundation
Lesson 15 Working with Tables
Positioning Objects with CSS and Tables
Sizing, Positioning, and Transforming Elements
Presentation transcript:

Introduction to Windows Presentation Foundation (WPF) Dr. Frank McCown COMP 445 – GUI Programming

WPF History Work began in early 2000’s by Microsoft under code name “Avalon” Effort to provide a clearer separation between the interface and business logic Avalon renamed WPF in July 2005 WPF released in 2006 as part of.NET Framework 3.0 Silverlight (released in 2007) is a subset of WPF Windows Phone 7 (released in 2010) uses Silverlight or XNA to write apps

WPF Features Works on top of DirectX to provide more advanced UI features Support for 2D and 3D graphics, audio, and video GUI appearance and content manipulated with XAML WPF controls can be embedded in Windows Forms app and vice versa Uses vector-based graphics for resolution independence WPF apps can stand alone or run in Internet Explorer

Bringing it all together…

Extensible Application Markup Language (XAML) Pronounced “zammel” XML-based markup language for defining and arranging GUI controls Can be manually generated/edited or edited by Visual Studio

Example XAML Document <Window x:Class="WPF_HelloWindows.Window1” xmlns=" xmlns:x=" Title="Hello WPF" Height="150" Width="250"> <Label Name="label1" VerticalAlignment="Center" HorizontalAlignment="Center">Hello, WPF! Window1.xaml

Control Layout Windows Forms: Set absolute (x,y) position WPF: Set relative position in its layout container Controls grow/shrink as window grows/shrinks Control properties: – Width, Height – MinWidth, MinHeight, MaxWidth, MaxHeight – Margin: space around control’s edges (L,T,R,B) – HorizontalAlignment (Left, Center, Right, or Stretch) – VerticalAlignment (Top, Center, Bottom, or Stretch)

Alignment Introduction to WPF Layout by Christian Moser

Padding and Margin Introduction to WPF Layout by Christian Moser The Margin is the extra space around the control. The Padding is extra space inside the control. The Padding of an outer control is the Margin of an inner control.

Common Layouts Grid Canvas StackPanel DockPanel WrapPanel

Grid Layout Grid Panel by Christian Moser Layout is defined by a grid of rows and columns with elements placed in cells.

Canvas Layout Canvas Panel by Christian Moser Elements are placed in relation to the distance from the top and left edges of the Canvas.

StackPanel Layout StackPanel by Christian Moser Elements are arranged in a single column or row.

DockPanel Layout Dock Panel by Christian Moser Elements are positioned based on the edge they are docked to.

WrapPanel Layout Wrap Panel by Christian Moser A wrapping StackPanel where elements are wrapped to the next row or column.

Event Handling Press Me // Code from Windows1.xaml.cs public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { label1.Content = "Button pressed!"; }

Event Routing All WPF events are routed events – Can travel up (from child to parent) – Can travel down (from parent to child) Three types of routed events – Direct events: Don’t travel up or down – Bubbling events: Travel up (Source to Window) – Tunneling events: Travel down (top of containment hierarchy to Source)

Bubbling Event Example <GroupBox Name="myGroupBox" Header="Bubbling Example“ MouseLeftButtonUp="MyCallback"> <Label Name="myLabel" MouseLeftButtonUp=“MyCallback"> Click Me private void MyCallback(object sender, MouseButtonEventArgs e) { // Label notified of event first, then GroupBox } Bubbling event

Tunneling Event Example <GroupBox Name="myGroupBox" Header="Bubbling Example“ PreviewMouseLeftButtonUp ="Tunneling"> <Label Name="myLabel" PreviewMouseLeftButtonUp="Tunneling"> Click Me private void Tunneling(object sender, MouseButtonEventArgs e) { // GroupBox notified of event first, then Label } Tunneling event

Commands Any action or task that may be triggered by different user interactions – Example: File  Exit from the menu and Exit button may both need to execute the same command Commands can better synchronize a tasks’ availability – Example: If copy command requires text to be highlighted, all controls using this command can be disabled if no text is highlighted Some common built-in commands: New, Open, Save, Close, Cut, Copy, Paste Can create your own custom commands

Command Example <Window x:Class="WPF_HelloWindows.Window1" xmlns=" xmlns:x=" Title="Hello WPF" Height="150" Width="250"> <Button Height="23" Margin=“80,0,80,14" Name="button1" VerticalAlignment="Bottom“ Command="Close">Press Me Called by Menu and Button

Styles WPF style is a collection of reusable property- value & event-handler definitions Concept is similar to style sheets for HTML Same Style might be applied to different types of controls Styles are WPF resources – Reusable objects defined for entire application

Styles Example 1 Same style applied to different controls

Styles Example 2

Control Templates Appearance of WPF controls determined by a control template Control template is a hierarchy of visual elements All visual controls use a default control template Changes to a control’s control template can redefine the appearance of the control without changing its functionality Button | Border | ContentPresenter | String Displays single element

Control Template Example <Border Name="Border" BorderThickness="2" CornerRadius="10" BorderBrush="BlueViolet"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" TextBlock.FontWeight="Bold" TextBlock.Foreground="Firebrick" Content="{TemplateBinding Content}" /> Button 1 <Button Name="button2" Width="100" Height="30" Template="{StaticResource MyButtonTemplate}"> Button 2

Triggers Triggers can be used to change a control’s appearance when it enters a certain state Can be used with Styles or Control Templates Must be defined in Style.Triggers or ControlTemplate.Triggers

Style with Trigger Example Push Me

Control Template with Trigger Example <Border Name="Border" BorderThickness="2" CornerRadius="10" BorderBrush="BlueViolet"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" TextBlock.FontWeight="Bold" TextBlock.Foreground="Firebrick" Content="{TemplateBinding Content}" /> <Setter TargetName="Border" Property="Background" Value="LightBlue" /> <Button Name="button2" Width="100" Height="30" Template="{StaticResource MyButtonTemplate}">Button 2 trigger