SlideShare a Scribd company logo
 User actions
 moves the mouse, clicks a button, presses a key,
or draws with a pen,…
 WPF provides
 events, commands, and triggers
 Functional definition: A routed event is a type
of event that can invoke handlers on multiple
listeners in an element tree, rather than just
on the object that raised the event.
 Implementation definition: A routed event is a
CLR event that is backed by an instance of
the RoutedEvent class and is processed by
theWPF event system.
 The event route for this Click event is:
Button-->StackPanel-->Border-->...
 Control composition and encapsulation
 Singular handler attachment points
 Attach handler one time for multiple elements
 Class handling
 Permit a static handler that is defined by the class
 Referencing an event without reflection
 Event identification that does not require static or
run-time reflection
 Bubbling: routes from element to root
 Direct: only source element invoke handlers
 Tunneling: routes from root to element
 Attached event allows you to attach an event
handler to some child element rather than to
the parent that actually defines the event
 Attached event enable elements to handle
events that are declared in a different
element
 Attached events are routed events that
support a hookup in XAML on elements other
than the type on which the event is declared
 Event Button.Click is attached for Grid element
Routed Events
 EventSetters
 Represented by the <EventSetter> tag that pre-
declared in Styles
 Sharing handler for multiple elements by Styles
 EventTriggers
 Represented by the <EventTrigger> tag that pre-
declared in Styles
 Specify an event and activate when that event is
raised
 Have an Actions collection
 Commands specify what can application do?
 Command is an action the application
performs at the user’s request
 Single handler for a command can enables for
multiple elements
 Command allows multiple and disparate
sources to invoke the same command logic
 Command example:
 Copy: Ctrl+C, EditCopy, Copy Button,...
 The command is the action to be executed.
 The command source is the object which
invokes the command.
 The command target is the object that the
command is being executed on.
 The command binding is the object which
maps the command logic to the command.
 A command object identifies a particular
command (such as copy or paste)
 Commands are created by implementing the
ICommand interface
Class Command types
ApplicationCommands Commands common to almost all applications. Includes
clipboard commands, undo and
redo, and document-level operations (open, close, print,
etc.).
ComponentCommands Operations for moving through information, such as scroll
up and down, move to end, and
text selection.
EditingCommands Text editing commands such as bold, italic, center, and
justify.
MediaCommands Media-playing operations such as transport (play, pause,
etc.), volume control, and track
selection.
NavigationCommands Browser-like navigation commands such as Back, Forward,
and Refresh.
 A command source is the object which
invokes the command (such as MenuItem,
Button,…)
 Command sources generally implement the
ICommandSource interface
 A CommandBinding associates a command
with the event handlers that implement the
command
<Window.CommandBindings>
<CommandBinding Command="ApplicationCommands.Open"
Executed="OpenCmdExecuted"
CanExecute="OpenCmdCanExecute"/>
</Window.CommandBindings>
 The command target is the element on which
the command is executed
 The command source can explicitly set the
command target
 If the command target is not defined, the
element with keyboard focus will be used as
the command target
 invoke a command on multiple targets without
having to keep track of the command target
 Implement the ICommand interface
 Create a RoutedCommand
 Create a RoutedUICommand.
Custom RoutedCommand
 Style, ControlTemplate, and DataTemplate
all have a Triggers property that can contain a
set of triggers.
 A trigger sets properties or starts actions
such as animation when a property value
changes or when an event is raised
 Used to apply setter elements to control by
conditions of dependency properties
<StyleTargetType="{x:Type Button}">
<Setter Property="Button.Background"Value="AliceBlue" />
<Style.Triggers>
<Trigger Property="IsMouseOver"Value="True">
<Setter Property="Button.Opacity"Value="1"></Setter>
<Setter Property="Button.Background"Value="Green"></Setter>
</Trigger>
</Style.Triggers>
</Style>
MultipleTriggers
Multiconditions
 Used to apply setter elements to control by
conditions of CLR properties (data binding)
 Also have multiple and multicondition
<StyleTargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Role}"Value="Admin">
<Setter Property="Foreground"Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
 Used to raising an animation to control by
watch for events
<EventTrigger RoutedEvent="UIElement.MouseEnter" SourceName="MyText">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames
Storyboard.TargetName="Popup"
Storyboard.TargetProperty="(Popup.IsOpen)">
<DiscreteBooleanKeyFrame KeyTime="00:00:00"Value="True"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
Triggers

More Related Content

What's hot

Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5sotlsoc
 
12 High Level UI Event Handling
12 High Level UI Event Handling12 High Level UI Event Handling
12 High Level UI Event Handlingcorneliuskoo
 
File Handling
File HandlingFile Handling
File Handling
Sohanur63
 
PROGRAMA DE EJEMPLO
PROGRAMA DE EJEMPLOPROGRAMA DE EJEMPLO
PROGRAMA DE EJEMPLOmhormech
 
Events1
Events1Events1
Events1
Nuha Noor
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
PRN USM
 
Código Opção Substituir
Código Opção SubstituirCódigo Opção Substituir
Código Opção Substituircymbron
 
Elementos del lenguaje
Elementos del lenguajeElementos del lenguaje
Elementos del lenguajeguest6473b8
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - eventsroxlu
 
Código Editor Net
Código Editor NetCódigo Editor Net
Código Editor Netcymbron
 
Latihan visual basic 2010/Looping/Perulangan
Latihan visual basic 2010/Looping/PerulanganLatihan visual basic 2010/Looping/Perulangan
Latihan visual basic 2010/Looping/Perulangan
Nurul Arhaiyyu
 
Controls in action
Controls in actionControls in action
Controls in action
SV.CO
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)
rishi ram khanal
 
Código Acerca Editor_Net
Código Acerca Editor_NetCódigo Acerca Editor_Net
Código Acerca Editor_Netcymbron
 
A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014
Matthias Noback
 

What's hot (20)

Event handling
Event handlingEvent handling
Event handling
 
Event handling
Event handlingEvent handling
Event handling
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Calculadora
CalculadoraCalculadora
Calculadora
 
12 High Level UI Event Handling
12 High Level UI Event Handling12 High Level UI Event Handling
12 High Level UI Event Handling
 
File Handling
File HandlingFile Handling
File Handling
 
PROGRAMA DE EJEMPLO
PROGRAMA DE EJEMPLOPROGRAMA DE EJEMPLO
PROGRAMA DE EJEMPLO
 
What is Event
What is EventWhat is Event
What is Event
 
Events1
Events1Events1
Events1
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
 
Código Opção Substituir
Código Opção SubstituirCódigo Opção Substituir
Código Opção Substituir
 
Elementos del lenguaje
Elementos del lenguajeElementos del lenguaje
Elementos del lenguaje
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - events
 
Código Editor Net
Código Editor NetCódigo Editor Net
Código Editor Net
 
Latihan visual basic 2010/Looping/Perulangan
Latihan visual basic 2010/Looping/PerulanganLatihan visual basic 2010/Looping/Perulangan
Latihan visual basic 2010/Looping/Perulangan
 
Controls in action
Controls in actionControls in action
Controls in action
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)
 
Código Acerca Editor_Net
Código Acerca Editor_NetCódigo Acerca Editor_Net
Código Acerca Editor_Net
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
 
A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014
 

Similar to Lesson 07 Actions and Commands in WPF

Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+featuresFaisal Aziz
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
sharanyak0721
 
WPF Fundamentals
WPF FundamentalsWPF Fundamentals
WPF Fundamentals
Our Community Exchange LLC
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
Ankit Dubey
 
Androd Listeners
Androd ListenersAndrod Listeners
Androd Listeners
ksheerod shri toshniwal
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
kashyapneha2809
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
nehakumari0xf
 
Javascript Browser Events.pdf
Javascript Browser Events.pdfJavascript Browser Events.pdf
Javascript Browser Events.pdf
ShubhamChaurasia88
 
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 Dr Jammi Ashok - Introduction to Java Material (OOPs) Dr Jammi Ashok - Introduction to Java Material (OOPs)
Dr Jammi Ashok - Introduction to Java Material (OOPs)
jammiashok123
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
WebStackAcademy
 
Event handling
Event handlingEvent handling
Java gui event
Java gui eventJava gui event
Java gui event
SoftNutx
 
event_handling.ppt
event_handling.pptevent_handling.ppt
event_handling.ppt
SarojKumar864774
 
EventBus for Android
EventBus for AndroidEventBus for Android
EventBus for Android
greenrobot
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event Model
Michael Heron
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
Jyothishmathi Institute of Technology and Science Karimnagar
 
Javascript #8 : événements
Javascript #8 : événementsJavascript #8 : événements
Javascript #8 : événements
Jean Michel
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
Payal Dungarwal
 
09events
09events09events
09events
Waheed Warraich
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
usvirat1805
 

Similar to Lesson 07 Actions and Commands in WPF (20)

Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
 
WPF Fundamentals
WPF FundamentalsWPF Fundamentals
WPF Fundamentals
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 
Androd Listeners
Androd ListenersAndrod Listeners
Androd Listeners
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
 
Javascript Browser Events.pdf
Javascript Browser Events.pdfJavascript Browser Events.pdf
Javascript Browser Events.pdf
 
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 Dr Jammi Ashok - Introduction to Java Material (OOPs) Dr Jammi Ashok - Introduction to Java Material (OOPs)
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Event handling
Event handlingEvent handling
Event handling
 
Java gui event
Java gui eventJava gui event
Java gui event
 
event_handling.ppt
event_handling.pptevent_handling.ppt
event_handling.ppt
 
EventBus for Android
EventBus for AndroidEventBus for Android
EventBus for Android
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event Model
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
 
Javascript #8 : événements
Javascript #8 : événementsJavascript #8 : événements
Javascript #8 : événements
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
 
09events
09events09events
09events
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 

More from Quang Nguyễn Bá

Lesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPFLesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPF
Quang Nguyễn Bá
 
Lesson 08 Documents and Printings in WPF
Lesson 08 Documents and Printings in WPFLesson 08 Documents and Printings in WPF
Lesson 08 Documents and Printings in WPF
Quang Nguyễn Bá
 
Lesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPFLesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPF
Quang Nguyễn Bá
 
Lesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPFLesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPF
Quang Nguyễn Bá
 
Lesson 04 WPF Controls
Lesson 04 WPF ControlsLesson 04 WPF Controls
Lesson 04 WPF Controls
Quang Nguyễn Bá
 
Lesson 03 Layouts in WPF
Lesson 03 Layouts in WPFLesson 03 Layouts in WPF
Lesson 03 Layouts in WPF
Quang Nguyễn Bá
 
Lesson 02 Introduction to XAML
Lesson 02 Introduction to XAMLLesson 02 Introduction to XAML
Lesson 02 Introduction to XAML
Quang Nguyễn Bá
 
Lesson 01 Introduction to WPF
Lesson 01 Introduction to WPFLesson 01 Introduction to WPF
Lesson 01 Introduction to WPF
Quang Nguyễn Bá
 
Business intelligence
Business intelligenceBusiness intelligence
Business intelligence
Quang Nguyễn Bá
 
TDD - Test Driven Dvelopment | Test First Design
TDD -  Test Driven Dvelopment | Test First DesignTDD -  Test Driven Dvelopment | Test First Design
TDD - Test Driven Dvelopment | Test First Design
Quang Nguyễn Bá
 
Scrum sử dụng Team Foundation Server 2012
Scrum sử dụng Team Foundation Server 2012Scrum sử dụng Team Foundation Server 2012
Scrum sử dụng Team Foundation Server 2012
Quang Nguyễn Bá
 
Introduction to Microsoft SQL Server 2008 R2 Integration Services
Introduction to Microsoft SQL Server 2008 R2 Integration ServicesIntroduction to Microsoft SQL Server 2008 R2 Integration Services
Introduction to Microsoft SQL Server 2008 R2 Integration ServicesQuang Nguyễn Bá
 
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2Introduction to Business Intelligence in Microsoft SQL Server 2008 R2
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2Quang Nguyễn Bá
 
Introduction to Microsoft SQL Server 2008 R2 Analysis Service
Introduction to Microsoft SQL Server 2008 R2 Analysis ServiceIntroduction to Microsoft SQL Server 2008 R2 Analysis Service
Introduction to Microsoft SQL Server 2008 R2 Analysis ServiceQuang Nguyễn Bá
 
SharePoint 2010 Business Intelligence
SharePoint 2010 Business IntelligenceSharePoint 2010 Business Intelligence
SharePoint 2010 Business IntelligenceQuang Nguyễn Bá
 
Programming SharePoint 2010 with Visual Studio 2010
Programming SharePoint 2010 with Visual Studio 2010Programming SharePoint 2010 with Visual Studio 2010
Programming SharePoint 2010 with Visual Studio 2010Quang Nguyễn Bá
 

More from Quang Nguyễn Bá (20)

Lesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPFLesson 09 Resources and Settings in WPF
Lesson 09 Resources and Settings in WPF
 
Lesson 08 Documents and Printings in WPF
Lesson 08 Documents and Printings in WPFLesson 08 Documents and Printings in WPF
Lesson 08 Documents and Printings in WPF
 
Lesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPFLesson 06 Styles and Templates in WPF
Lesson 06 Styles and Templates in WPF
 
Lesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPFLesson 05 Data Binding in WPF
Lesson 05 Data Binding in WPF
 
Lesson 04 WPF Controls
Lesson 04 WPF ControlsLesson 04 WPF Controls
Lesson 04 WPF Controls
 
Lesson 03 Layouts in WPF
Lesson 03 Layouts in WPFLesson 03 Layouts in WPF
Lesson 03 Layouts in WPF
 
Lesson 02 Introduction to XAML
Lesson 02 Introduction to XAMLLesson 02 Introduction to XAML
Lesson 02 Introduction to XAML
 
Lesson 01 Introduction to WPF
Lesson 01 Introduction to WPFLesson 01 Introduction to WPF
Lesson 01 Introduction to WPF
 
Business intelligence
Business intelligenceBusiness intelligence
Business intelligence
 
TDD - Test Driven Dvelopment | Test First Design
TDD -  Test Driven Dvelopment | Test First DesignTDD -  Test Driven Dvelopment | Test First Design
TDD - Test Driven Dvelopment | Test First Design
 
Scrum sử dụng Team Foundation Server 2012
Scrum sử dụng Team Foundation Server 2012Scrum sử dụng Team Foundation Server 2012
Scrum sử dụng Team Foundation Server 2012
 
Introduction to Microsoft SQL Server 2008 R2 Integration Services
Introduction to Microsoft SQL Server 2008 R2 Integration ServicesIntroduction to Microsoft SQL Server 2008 R2 Integration Services
Introduction to Microsoft SQL Server 2008 R2 Integration Services
 
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2Introduction to Business Intelligence in Microsoft SQL Server 2008 R2
Introduction to Business Intelligence in Microsoft SQL Server 2008 R2
 
Introduction to Microsoft SQL Server 2008 R2 Analysis Service
Introduction to Microsoft SQL Server 2008 R2 Analysis ServiceIntroduction to Microsoft SQL Server 2008 R2 Analysis Service
Introduction to Microsoft SQL Server 2008 R2 Analysis Service
 
Office 2010 Programming
Office 2010 ProgrammingOffice 2010 Programming
Office 2010 Programming
 
Giới thiệu WCF
Giới thiệu WCFGiới thiệu WCF
Giới thiệu WCF
 
MOSS 2007 Overview
MOSS 2007 OverviewMOSS 2007 Overview
MOSS 2007 Overview
 
SharePoint Programming Basic
SharePoint Programming BasicSharePoint Programming Basic
SharePoint Programming Basic
 
SharePoint 2010 Business Intelligence
SharePoint 2010 Business IntelligenceSharePoint 2010 Business Intelligence
SharePoint 2010 Business Intelligence
 
Programming SharePoint 2010 with Visual Studio 2010
Programming SharePoint 2010 with Visual Studio 2010Programming SharePoint 2010 with Visual Studio 2010
Programming SharePoint 2010 with Visual Studio 2010
 

Recently uploaded

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 

Recently uploaded (20)

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 

Lesson 07 Actions and Commands in WPF

  • 1.
  • 2.  User actions  moves the mouse, clicks a button, presses a key, or draws with a pen,…  WPF provides  events, commands, and triggers
  • 3.
  • 4.  Functional definition: A routed event is a type of event that can invoke handlers on multiple listeners in an element tree, rather than just on the object that raised the event.  Implementation definition: A routed event is a CLR event that is backed by an instance of the RoutedEvent class and is processed by theWPF event system.
  • 5.  The event route for this Click event is: Button-->StackPanel-->Border-->...
  • 6.  Control composition and encapsulation  Singular handler attachment points  Attach handler one time for multiple elements  Class handling  Permit a static handler that is defined by the class  Referencing an event without reflection  Event identification that does not require static or run-time reflection
  • 7.  Bubbling: routes from element to root  Direct: only source element invoke handlers  Tunneling: routes from root to element
  • 8.  Attached event allows you to attach an event handler to some child element rather than to the parent that actually defines the event  Attached event enable elements to handle events that are declared in a different element  Attached events are routed events that support a hookup in XAML on elements other than the type on which the event is declared
  • 9.  Event Button.Click is attached for Grid element
  • 11.  EventSetters  Represented by the <EventSetter> tag that pre- declared in Styles  Sharing handler for multiple elements by Styles  EventTriggers  Represented by the <EventTrigger> tag that pre- declared in Styles  Specify an event and activate when that event is raised  Have an Actions collection
  • 12.
  • 13.
  • 14.
  • 15.  Commands specify what can application do?  Command is an action the application performs at the user’s request  Single handler for a command can enables for multiple elements  Command allows multiple and disparate sources to invoke the same command logic  Command example:  Copy: Ctrl+C, EditCopy, Copy Button,...
  • 16.  The command is the action to be executed.  The command source is the object which invokes the command.  The command target is the object that the command is being executed on.  The command binding is the object which maps the command logic to the command.
  • 17.  A command object identifies a particular command (such as copy or paste)  Commands are created by implementing the ICommand interface
  • 18. Class Command types ApplicationCommands Commands common to almost all applications. Includes clipboard commands, undo and redo, and document-level operations (open, close, print, etc.). ComponentCommands Operations for moving through information, such as scroll up and down, move to end, and text selection. EditingCommands Text editing commands such as bold, italic, center, and justify. MediaCommands Media-playing operations such as transport (play, pause, etc.), volume control, and track selection. NavigationCommands Browser-like navigation commands such as Back, Forward, and Refresh.
  • 19.  A command source is the object which invokes the command (such as MenuItem, Button,…)  Command sources generally implement the ICommandSource interface
  • 20.  A CommandBinding associates a command with the event handlers that implement the command <Window.CommandBindings> <CommandBinding Command="ApplicationCommands.Open" Executed="OpenCmdExecuted" CanExecute="OpenCmdCanExecute"/> </Window.CommandBindings>
  • 21.  The command target is the element on which the command is executed  The command source can explicitly set the command target  If the command target is not defined, the element with keyboard focus will be used as the command target  invoke a command on multiple targets without having to keep track of the command target
  • 22.
  • 23.  Implement the ICommand interface  Create a RoutedCommand  Create a RoutedUICommand.
  • 25.
  • 26.  Style, ControlTemplate, and DataTemplate all have a Triggers property that can contain a set of triggers.  A trigger sets properties or starts actions such as animation when a property value changes or when an event is raised
  • 27.  Used to apply setter elements to control by conditions of dependency properties <StyleTargetType="{x:Type Button}"> <Setter Property="Button.Background"Value="AliceBlue" /> <Style.Triggers> <Trigger Property="IsMouseOver"Value="True"> <Setter Property="Button.Opacity"Value="1"></Setter> <Setter Property="Button.Background"Value="Green"></Setter> </Trigger> </Style.Triggers> </Style>
  • 29.  Used to apply setter elements to control by conditions of CLR properties (data binding)  Also have multiple and multicondition <StyleTargetType="{x:Type ListBoxItem}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=Role}"Value="Admin"> <Setter Property="Foreground"Value="Red" /> </DataTrigger> </Style.Triggers> </Style>
  • 30.  Used to raising an animation to control by watch for events <EventTrigger RoutedEvent="UIElement.MouseEnter" SourceName="MyText"> <BeginStoryboard> <Storyboard> <BooleanAnimationUsingKeyFrames Storyboard.TargetName="Popup" Storyboard.TargetProperty="(Popup.IsOpen)"> <DiscreteBooleanKeyFrame KeyTime="00:00:00"Value="True"/> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger>

Editor's Notes

  1. Top-level Scenarios for Routed Events The following is a brief summary of the scenarios that motivated the routed event concept, and why a typical CLR event was not adequate for these scenarios: Control composition and encapsulation: Various controls in WPF have a rich content model. For example, you can place an image inside of a Button, which effectively extends the visual tree of the button. However, the added image must not break the hit-testing behavior that causes a button to respond to a Click of its content, even if the user clicks on pixels that are technically part of the image. Singular handler attachment points: In Windows Forms, you would have to attach the same handler multiple times to process events that could be raised from multiple elements. Routed events enable you to attach that handler only once, as was shown in the previous example, and use handler logic to determine where the event came from if necessary. For instance, this might be the handler for the previously shown XAML: Class handling: Routed events permit a static handler that is defined by the class. This class handler has the opportunity to handle an event before any attached instance handlers can. Referencing an event without reflection: Certain code and markup techniques require a way to identify a specific event. A routed event creates a RoutedEvent field as an identifier, which provides a robust event identification technique that does not require static or run-time reflection.
  2. Bubbling: Event handlers on the event source are invoked. The routed event then routes to successive parent elements until reaching the element tree root. Most routed events use the bubbling routing strategy. Bubbling routed events are generally used to report input or state changes from distinct controls or other UI elements. Direct: Only the source element itself is given the opportunity to invoke handlers in response. This is analogous to the "routing" that Windows Forms uses for events. However, unlike a standard CLR event, direct routed events support class handling (class handling is explained in an upcoming section) and can be used by EventSetter and EventTrigger. Tunneling: Initially, event handlers at the element tree root are invoked. The routed event then travels a route through successive child elements along the route, towards the node element that is the routed event source (the element that raised the routed event). Tunneling routed events are often used or handled as part of the compositing for a control, such that events from composite parts can be deliberately suppressed or replaced by events that are specific to the complete control. Input events provided in WPF often come implemented as a tunneling/bubbling pair. Tunneling events are also sometimes referred to as Preview events, because of a naming convention that is used for the pairs.
  3. The routed command model in WPF can be broken up into four main concepts: the command, the command source, the command target, and the command binding: The command is the action to be executed. The command source is the object which invokes the command. The command target is the object that the command is being executed on. The command binding is the object which maps the command logic to the command.