Windows Presentation Foundation (WPF). Introduction Separates appearance of user interface from behavior Appearance usually specified by XAML Behavior.

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

 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
Dinko Jakovljević Microsoft Student Partner | BambooLab
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Microsoft Excel 2010 Chapter 7
Web Development in Microsoft Visual Studio Slide 2 Lecture Overview Introduce Visual Studio 2013 Create a first ASP.NET application.
1 Chapter 12 Working With Access 2000 on the Internet.
Integrating Access with the Web and with Other Programs.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Visual Basic Chapter 1 Mr. Wangler.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Microsoft Visual Basic 2005: Reloaded Second Edition
V 1.0 Programming III. Creation of additional windows Routed events.
1 COS240 O-O Languages AUBG, COS dept Lecture 33 Building Apps Technologies C# (WPF part 1)
An Introduction to Silverlight Matt Harrington Developer Evangelist, Microsoft October 20, 2011.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Week 2: WINDOWS PROGRAMMING Chapter 15 in “Beginning Visual C# 2010” ebook Chapter 4 in “”MCTS_Self-Paced_Training_Kit” ebook.
Virtual techdays INDIA │ Nov 2010 Developing Office Biz Application using WPF on Windows 7 Sarang Datye │ Sr. Consultant, Microsoft Sridhar Poduri.
Windows Presentation Foundation Adam Calderon Principal Engineer Interknowlogy LLC
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Dr Dat Tran - Week 4 Lecture Notes 1 ToolStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
V 1.1 Programming III. Creating additional windows Event handling: preview/routed events.
V 1.0 Programming III. Automatic notifications (…Changed, INofityPropertyChanged, ObservableCollection ) Data formatters Data conversions Resources.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
Chapter Two Creating a First Project in Visual Basic.
1 Chapter 12: Form Builder Objects and Flexible Code.
This eCPIC Quick Guide has been developed to assist System Administrators with creating Hierarchy Grids in eCPIC. The Hierarchy Grid functionality allows.
Object Oriented Software Development 10. Persistent Storage.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Page Designer Storyboard J. A. Fitzpatrick December 2004.
XP Tutorial 8 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Object Linking and Embedding Tutorial 8.
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
V 1.0 Programming III. Automatic notifications with data binding (…Changed, INofityPropertyChanged, ObservableCollection, DataTemplate) Data formatters.
CPSC 481 – Week #7 Sowmya Somanath
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 8 1 Microsoft Office Access 2003 Tutorial 8 – Integrating Access with the.
Module 1 Introducing C# and the.NET Framework. Module Overview Introduction to the.NET Framework 4 Creating Projects Within Visual Studio 2010 Writing.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Part of the Microsoft.NET Framework 3.0 Tomer Shamam.NET Technologies Expert Sela Group
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
Introduction to Silverlight
Chapter 2 – Introduction to the Visual Studio .NET IDE
Introduction to Silverlight
XAML User Interface Creation in C#
WPF AKEEL AHMED.
CIS16 Application Development Programming with Visual Basic
Gathering User Input Event Handling Create Dynamic controls
Static and Dynamic Web Pages
Web Development Using ASP .NET
Week 2: WINDOWS PROGRAMMING
Presentation transcript:

Windows Presentation Foundation (WPF)

Introduction Separates appearance of user interface from behavior Appearance usually specified by XAML Behavior implemented in C# or VB Known as "managed languages" Linked by "data binding" & events XML can be created with graphical tools "Controls" can be combined ("composed") Image & text in a button

XAML language Includes language-level features to associate code files with markup files, from the markup file side. Defines the language features x:Class Directive x:Subclass Directive x:ClassModifier Directive. x:ClassModifier Directive Does NOT specify how the code should be produced how to integrate markup and code, It is left up to frameworks such as WPF to determine how to integrate the code, how to use XAML in the application and programming models, and the build actions or other support that all this requires.

Intro - 2 Controls are therefore customizable Create "skins" for an interface using "styles" Similar to CSS "Code Behind" the code that is joined with markup-defined objects, when a XAML page is markup-compiled Avoid or limit the use of inline code (inside XAML) Your event handlers in the Code Behind must be instance methods cannot be static methods must be defined by the partial class within the CLR namespace identified by x:Class.

A button & its properties Button code added by VS

Adding an event handler 1. Click the "lightning" icon on the Properties tab, to get this list of handlers 2. Double-Click the gray square to get the code added

Code added for my form private void Button_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("button clicked"); Application.Current.Shutdown();// terminates the program } private void CheckBox_Checked(object sender, RoutedEventArgs e) { // here you can add code to save the setting of the checkbox } object sender – which control caused the interrupt RoutedEventArgs e – what the control did DialogResult result = Form1().ShowDialog(); is any content from the control

XAML & WPF XAML element corresponds to a WPF class Element's attributes have corresponding property/event in the class. Example, No Or use C#: Button btn = new Button(); btn.Background = Brushes.Red; btn.Content = "No";

WPF example – part 1 Click Me! The x:Class associates these 2 elements of the project: XAML def'n of window (above) code-behind class (MyWindow) on next slide This example (parts 1 & 2) is from: Same as namespace Same as main window

WPF example –part 2 using System.Windows; // Window, RoutedEventArgs, MessageBox namespace SDKSample { public partial class MyWindow : Window { public MyWindow() { // InitializeComponent call is required to merge the UI // that is defined in markup with this class, including // setting properties and registering event handlers InitializeComponent(); } void button1_Click(object sender, RoutedEventArgs e) { // Show message box when button is clicked MessageBox.Show("Hello, from WPF app!"); }

Events WPF events are "routed" May traverse a hierarchy of handlers May be handled by more than 1 handler Last "desired" handler sets the "handled" property to "true" Stops all further handling "Source" property saves origin of event 3 types: Direct events – similar to Windows Forms events – no hierarchy traversal Bubbling events – start at the Source and travel UP the hierarchy to the Window Tunneling events - start at the Window and travel DOWN the hierarchy Prefixed with "Preview" (e.g.; PreviewMouseLeftButton) An event handler can handle events for > 1 control To specify this: Select the control Use the Events tab in the Properties window Reference:

Commands Provide alternate ways of creating events Similar to MFC and Win32API Menu bars provide "labels" for actions Allows synch between command and program "state" "copy" can only be done if something is "selected" Invalid commands can be greyed-out Many standard commands built-in Copy, Cut, Paste Open, Save, Close, New ToggleBold, ToggleItalic, ToggleUnderline Play, Stop, Rewind

Resources Describe the objects your project uses Provides means to "bind" resources to code Two types of Resources Static Dynamic Two types of Resource Files: Linked External files.resx file includes only a relative path Embedded Inside the.resx file of the project

Adding Resources Right-click the Properties node under the project in Solution Explorer Click "Open" Click Add Resource button (top of the Resources page in Project Designer)

Sample text to Datagrid Data source is created using an ObservableCollection of a custom class in the window’s code-behind script This is not always the best approach to take – you will usually be using DataAdapters and DataTables to retrieve information from a database, or external files Setting the grid’s ItemSource property to inherit from the data context creates the binding between grid & data. After the collection is populated, set Grid.DataContext = collection_name; causes the user interface to update and display the grid content.

XAML & Code-behind using System; using System.Collections.ObjectModel; using System.Windows; namespace Wpf_userlist { public class User//our observable collection class { private String _n; private int _n1; public String name// "name" will be bound to collection { get { return _n; } set { _n = value; } // value is set on next slide } public int int1 // "int1" will be bound to collection { get { return _n1; } set { _n1 = value; } }

Create Observable Collection public partial class MainWindow : Window { public ObservableCollection User = new ObservableCollection(); public MainWindow() { InitializeComponent(); // next 2 lines to be replaced by file reading data.Add(new User() {Name="Foreman", int1=1}); data.Add(new User() {Name ="Smith", int1=2}); myGrid.DataContext = User; } } // end of partial class MainWindow } // end of program

Read a file // Read a file and display it line by line. System.IO.StreamReader myFile = new System.IO.StreamReader("c:\\test.txt"); while((line = file.ReadLine()) != null) { process_line(line); // move line into data array } OR string[] lines = myFile.Close();

Using a datagrid Here’s a really good tutorial on getting data into a datagrid. But it uses "predefined" data. You need a file-read. Here’s a short example (lots of details omitted) from my own code: private void process_line (String x) { string thename; String[] ints; ints = x.Substring(position of 2 nd quote+2).Split(','); csvlist.Add (new csvrow() { name = thename, int1 = ints[0], int2=ints[1] }); // MessageBox.Show("name="+ csvlist[0].name); } csvlist is a List of type csvrow, where csvrow is a C# class that specifies the names of the columns of the datagrid. Split is a member that separates-out the elements of a string Process_line is called after each whole line of input is obtained Remember to instantiate everything: csvlist = new List (); datagrid Userdata_DG1 = new DataGrid();