Brown Bag Seminar Summer 2007

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

OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
A Scalable Application Architecture for composing News Portals on the Internet Serpil TOK, Zeki BAYRAM. Eastern MediterraneanUniversity Famagusta Famagusta.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
An Introduction to Silverlight Matt Harrington Developer Evangelist, Microsoft October 20, 2011.
Windows Presentation Foundation Adam Calderon Principal Engineer Interknowlogy LLC
Object Oriented Software Development 9. Creating Graphical User Interfaces.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
JavaScript - A Web Script Language Fred Durao
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.
A Lap Around Windows Presentation Foundation. Why hasn’t UX taken off in software? It’s Difficult! Animation 2D 3D Documents Styled Controls Video Windows.
Windows Presentation Foundation (WPF). Introduction Separates appearance of user interface from behavior Appearance usually specified by XAML Behavior.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
CPSC 871 John D. McGregor Module 3 Session 1 Architecture.
Object Oriented Programming.  Interface  Event Handling.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
Forms and Controls Part 3 dbg --- Naming conventions, Button, Event handlers, Label.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
Part of the Microsoft.NET Framework 3.0 Tomer Shamam.NET Technologies Expert Sela Group
Lecture 15 Basic GUI programming
Jim Fawcett, Brown Bag Seminar Series Fall 2007
CSC 205 Programming II Lecture 5 AWT - I.
Dive Into® Visual Basic 2010 Express
Introduction to Silverlight
CompSci 230 S Software Construction
Important New Concepts In WPF
Microsoft Office Ribbon
Introduction to Event-Driven Programming
Chapter 8: Writing Graphical User Interfaces
Jim Fawcett, Brown Bag Seminar Series Fall 2007
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
Computer Applications for Business
Unit 2 User Interface Design.
Introduction to Silverlight
XAML User Interface Creation in C#
Introduction to Programming the WWW I
Understand Windows Forms Applications and Console-based Applications
Lesson 1: Buttons and Events – 12/18
CSE 331 Software Design and Implementation
Introduction to Events
Programming in Java Event Handling
Windows Desktop Applications
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Fundamentals of Python: From First Programs Through Data Structures
Event Driven Programming
EE 422C Java FX.
WPF AKEEL AHMED.
.NET and .NET Core 7. XAML Pan Wuming 2017.
Introduction to Computing Using Java
CSE 331 Software Design and Implementation
Microsoft Office Ribbon
Event Driven Programming
GRAPHICAL USER INTERFACE
Visual programming Chapter 2: Events and Event Handling
1/10/2019 JavaFX Events COSC 330.
Lecture Set 11 Creating and Using Classes
Event Driven Systems and Modeling
An Introduction to Software Architecture
Event loops 17-Jan-19.
.NET and .NET Core 8. WPF Hierarchy Pan Wuming 2017.
Web Development Using ASP .NET
Constructors, GUI’s(Using Swing) and ActionListner
Microsoft Office Ribbon
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
ACM programming contest
Running Your Visual Basic Program
Presentation transcript:

Brown Bag Seminar Summer 2007 Actions Brown Bag Seminar Summer 2007

Actions – Brown Bag Seminar Often we want an application to respond in some way when a user moves the mouse, clicks a button, presses a key, or draws with a pen. Windows Presentation Foundation has three common ways of dealing with actions: Events Commands Triggers We will look at the principles that apply to all three of these mechanisms, and then dig into the details about each one. Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Action Principles element composition loose coupling declarative actions Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Element Composition Remember the three principles of the control model Element composition rich content everywhere simple programming model Example of simple programming model Button b = new Button(); b.Content = "Click Me"; b.Click += delegate { MessageBox.Show("You clicked me!"); }; Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Element Composition Its not the button itself that is being clicked, but rather the elements that make up the display of the button Modified version of previous code snippet Button b = new Button(); b.Content = new Button(); b.Click += delegate { MessageBox.Show("You clicked me!"); }; Concept of routed events Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Element Composition Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Loose Coupling Semantic events (click) vs. physical events (MouseUp, MouseDown) Writing code against the Click event has two advantages We don’t tie ourselves to a specific input gesture (mouse versus keyboard) We don’t tie ourselves to a button. CheckBox, RadioButton, Button, and Hyperlink all support clicking. Code written against the Click event depends only on a component that can be clicked. This decoupling of code to the action produced allows for more flexibility in the implementation of handlers Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Loose Coupling Events themselves, though, suffer from a form of coupling that requires the method implementation to be of a specific signature. For example, the delegate for Button.Click is defined as follows: public delegate void RoutedEventHandler(object sender, RoutedEventArgs e); Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Loose Coupling One of the goals in WPF is to allow a spectrum of actions, ranging from tightly coupled physical events (like MouseUp) all the way to completely semantic notifications (like the ApplicationCommands.Close command that signals that a window should be closed). Actions – Brown Bag Seminar

Loose Coupling template for a window that adds chrome for closing the window Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Loose Coupling Loose coupling provides a complete abstraction from the action source (in this case, the button) and the action handler (in this case, the window). Leveraging this loose coupling, we could change the window style to use a totally different control and not break anything. Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Declarative Actions WPF is moving toward a model in which software declares its intent e.g., I want the window to close when you issue this command instead of its implementation e.g., Call Window.Close() when you click this button Events allow us to declare the target function in markup, but the handler must be implemented in code. Commands are specifically designed for declarative use, providing the best abstraction between the action source and consumer. Triggers provide probably the richest declarative support, but their lack of extensibility makes them difficult to use for complex tasks. Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Events In WPF, events behave exactly as they do in any other .NET class library. Each object exposes a set of events to which we can attach a listener using a delegate. There are three types of routed events: Direct Bubbling tunneling events Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Direct Events Direct events are simple events that fire on a single source; these are nearly identical to standard .NET events, with the exception that they are registered with the WPF routed-event system. The routed-event system is the part of WPF that is responsible for routing events through the element tree. This system is mostly hidden, with only small parts of it, like EventManager, RegisterRoutedEvent visible. Certain features in the platform (triggers, for example) require an event to be registered to be used. Actions – Brown Bag Seminar

Bubbling and Tunneling Events Actions – Brown Bag Seminar

Bubbling and Tunneling Events Tunneling events travel from the root of the element tree to a target element, and bubbling events do the opposite. Typically, these two types of events are paired, and the tunneling version is prefixed with Preview. Most input events (keyboard, mouse, and pen) have bubbling and tunneling versions of each event for example, MouseRightButtonDown and PreviewMouseRightButtonDown, respectively. Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Commands Used to deal with things more abstractly. Suppose we want to add the ability to quit We will first define the menu in the markup file: In the code behind, we can implement the event handler: Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Commands This works fine, but now lets also add a text section that includes a hyperlink to exit the application: We’re making a lot of assumptions about the implementation of ExitClicked. the signature is compatible with the Hyperlink.Click We now have arbitrary methods in the code behind baked into the markup file, so a graphic designer trying to build the UI for this application would have no idea what event handlers to bind to. Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Commands Commands exist to help solve this problem. They allow us to provide a single name to signify the action that we want. To start using commands, must do three things: define a command define the implementan of that command create a trigger for the command Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Commands Defining a new command: Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Commands To bind a menu item or hyperlink to Exit command: Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Commands Actions – Brown Bag Seminar

Actions – Brown Bag Seminar Trigger Triggers are signaled by three things: The state of a display property (Trigger) The state of a data property (DataTrigger) An event (EventTrigger) Allthree trigger types cause a set of actions when they are signaled Actions – Brown Bag Seminar

Adding Triggers to Data Actions – Brown Bag Seminar

Adding Triggers to Data Actions – Brown Bag Seminar

Adding Triggers to Data Actions – Brown Bag Seminar

Adding Triggers to Data Actions – Brown Bag Seminar