My XML is Alive! An Intro to XAML

Jeremy Likness
Jeremy LiknessSr. Cloud Developer Advocate at Microsoft
Consulting/Training
My XML is Alive! (An Intro to XAML)
Consulting/Training
consulting
Wintellect helps you build better software,
faster, tackling the tough projects and solving
the software and technology questions that
help you transform your business.
 Architecture, Analysis and Design
 Full lifecycle software development
 Debugging and Performance tuning
 Database design and development
training
Wintellect's courses are written and taught by
some of the biggest and most respected names
in the Microsoft programming industry.
 Learn from the best. Access the same
training Microsoft’s developers enjoy
 Real world knowledge and solutions on
both current and cutting edge
technologies
 Flexibility in training options – onsite,
virtual, on demand
Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull
out all the stops to help our customers achieve their goals through advanced software-based
consulting and training solutions.
who we are
About Wintellect
Consulting/Training
 Imperative to Declare
 XAML
 Data-binding
 Notify Property Change
 Design-time Data
 The Visual Tree
 Value Converters
 Dependency Objects and Properties
 Attached Properties and Behaviors
 The Visual State Manager
 MVVM
Agenda
Consulting/Training
 Imperative programming is the traditional
approach to writing code. You just … write it.
 Declarative programming lets you focus more
on structure or tasks and leaves the solution to
the compiler (or interpreter, or runtime).
 Imperative is more testable and gives you more
control over the implementation details.
 Declarative tends to be more readable and
accessible to non-developers (such as
designers).
Imperative to Declare
Consulting/Training
// imperative (long)
var productNames = new List<string>();
foreach(var p in Products)
{
if (p.Price <= 9.99)
{
productNames.Add(p.ProductName);
}
}
// a little of both (short with LINQ)
var productNames =
from p in Products
where p.Price <= 9.99
select p.ProductName;
// declarative (long with LINQ)
var productNames = Products.Where(p => p.Price <= 9.99).Select(p => p.ProductName);
Example of Imperative vs. Declarative
How to filter the product
How to project the product name
What to filter
What to project
Consulting/Training
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="myBindingConfiguration" closeTimeout="00:01:00" />
</basicHttpBinding>
</bindings>
<services>
<service name="MyNamespace.myServiceType">
<endpoint
address="myAddress" binding="basicHttpBinding"
bindingConfiguration="myBindingConfiguration"
contract="MyContract" />
</service>
</services>
</system.serviceModel>
</configuration>
WCF can be Declarative…
What, what, and what
Consulting/Training
BasicHttpBinding myBinding = new BasicHttpBinding();
EndpointAddress myEndpoint = new EndpointAddress("myAddress");
ChannelFactory<MyContract> myChannelFactory = new
ChannelFactory<MyContract>(myBinding, myEndpoint);
MyContract wcfClient = myChannelFactory.CreateChannel();
…or WCF can be Imperative
How, how, how …
Consulting/Training
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>I Hereby Declare</title>
<meta name="description" content="I Hereby Declare">
<meta name="author" content="Jeremy Likness">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>This is the Heading</h1>
<p>Can you get a sense of the structure from this?
</body>
</html>
HTML is Declarative…
Consulting/Training
<?xml version="1.0">
<note>
<to>Jeremy Likness</to>
<from>Me</from>
<body>Do not forget to show the XML example.</body>
</note>
…and so is XML
Consulting/Training
 eXtensible Application Markup Language
 Pronounced “Zammel” (rhymes with “Camel”)
 An open specification by Microsoft
 XAML *is* XML
 Instantiates classes and initializes values and properties
 Used in WPF, Silverlight (including Windows Phone
apps), Windows Workflow Foundation, and the
Windows Runtime
 XML  CLR (or WinRT) that is language independent
 The same XAML can be used whether you are writing
your imperative code in C#, VB.NET, or even C++
XAML
Consulting/Training
Calculator
Consulting/Training
 XAML instantiates classes
 XAML populates properties
 UI Elements can be declared with XAML
 UI Elements have a special feature called “data-
binding”
 Data-binding can be used to view data
 Anything that can be declared in XAML can be
written with code!
What Did We Learn?
Consulting/Training
var page = new Page();
var grid = new Grid();
page.Content = new Grid();
var textBlock = new TextBlock();
var binding = new Binding
{
Path = new PropertyPath("Result")
};
textBlock.SetBinding(TextBlock.TextProperty, binding);
grid.Children.Add(textBlock);
grid.DataContext = new object(); // calculator here
XAML  Code
Consulting/Training
<TextBlock
Style="{StaticResource HeaderTextStyle}"
Text="{Binding Path=Result}"/>
Quick Decomposition
Create an instance of the
TextBlock WinRT component
Set the Style property of the
TextBlock
Moustaches are for markup
extensions. They will instantiate
the “StaticResource” class and
pass the “HeaderTextStyle”
parameter
This one uses a named parameter with the
special Binding markup extension. Binding is
what makes XAML magic for UI.
Consulting/Training
Data-Binding
Source (Data)
Target
(Framework
Element)
Data-Binding
Component
One-Way One-Way
Two-Way
Consulting/Training
Data-Binding
Consulting/Training
Data-Binding
Consulting/Training
 Simple interface to implement on your class
 Whenever you want data-binding to “know”
about changes (typically whenever a property
is updated) you raise an event with the
property name
 Empty property name means “all properties are
suspect”
 Also similar interface and events for collections
(observable collections)
Notify Property Change
Consulting/Training
 Very powerful – you don’t want to “design in
the dark”
 You can implement this several ways, including
“design-aware classes”
 Visual Studio 2013 has support for data files
(such as JSON)
 Specify a data source and type, or an instance
and “is design-time creatable”
Design-time Data
Consulting/Training
The Visual Tree
Consulting/Training
Value Converters
Consulting/Training
 Helps separate the data from the information (the
raw “stuff” from the presentation)
 Takes in one value, spits out another value
 Works equally well on primitives and complex
types
 Typically one way (for presentation) however can
be both ways in case you want to take user input
and map it back to an internal instance
 Avoid things like string-formatting, data
preparation, etc. in your model, instead use the
built-in XAML constructs to do this in the view
Value Converters
Consulting/Training
 Provides the “dependency property system”
designed to compute values of properties from
multiple sources (XAML configuration, animations,
styles, data-binding, etc.) and provide system
notification when values have changed
 Properties are registered with the system and
exposes as CLR properties that pass information
back and forth to the underlying object
 Common base for most XAML UI elements – allows
them to bind to each other, to data sources, etc.
 Provides inheritance, i.e. “data context” can be set
at a parent level and propagate to children
Dependency Objects and Properties
Consulting/Training
Attached Properties
Consulting/Training
 Used to extend functionality or apply a common
behavior to existing elements
 For example, an element doesn’t “know” about grid
rows and columns, but attached properties extend
elements to allow them to specify what cells to appear
in when a grid is rendered
 If you find you are performing a common operation
(such as listening to text change events to update
data-bindings) consider encapsulating in a behavior
 Behaviors are independently testable and then
reusable and can be applied across existing elements
 Use dependency properties to save/recall values
Attached Properties and Behaviors
Consulting/Training
The Visual State Manager
Consulting/Training
 Again helps to separate the UI from the code
logic
 Declarative way to map states to their visual
representation
 Rich support for animations
 Transitions to emphasize the shift between
states
 Orthogonal groups
 Mutually exclusive states
The Visual State Manager
Consulting/Training
Model-View-ViewModel (MVVM)
Consulting/Training
 At the basic level means you have a class that
exposes properties for data-binding and holds the
state of the presentation
 Commands are a special type of data-bound
“action”
 Plenty of libraries but WinRT XAML has plenty to
support it “out of the box”
 Don’t be afraid of code-behind when it relates to
the UI (presentation) piece – after all, it is just an
extension of the classes that are declared by XAML
 Reuse across platforms (phone, Windows 8, etc.)
Model-View-ViewModel
Consulting/Training
 Imperative to Declare
 XAML
 Data-binding
 Notify Property Change
 Design-time Data
 The Visual Tree
 Value Converters
 Dependency Objects and Properties
 Attached Properties and Behaviors
 The Visual State Manager
 MVVM
Recap
Consulting/Training
Subscribers Enjoy
 Expert Instructors
 Quality Content
 Practical Application
 All Devices
Wintellect’s On-Demand
Video Training Solution
Individuals | Businesses | Enterprise Organizations
WintellectNOW.com
Authors Enjoy
 Royalty Income
 Personal Branding
 Free Library Access
 Cross-Sell
Opportunities
Try It Free!
Use Promo Code:
LIKNESS-13
Consulting/Training
Questions?
jlikness@Wintellect.com
Source Code:
http://bit.ly/16ScWyM
1 of 32

Recommended

Enterprise TypeScript by
Enterprise TypeScriptEnterprise TypeScript
Enterprise TypeScriptJeremy Likness
6.1K views14 slides
The Windows Runtime and the Web by
The Windows Runtime and the WebThe Windows Runtime and the Web
The Windows Runtime and the WebJeremy Likness
2.6K views37 slides
Windows 8.1 Sockets by
Windows 8.1 SocketsWindows 8.1 Sockets
Windows 8.1 SocketsJeremy Likness
3.3K views27 slides
Single Page Applications: Your Browser is the OS! by
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Jeremy Likness
4.9K views39 slides
Getting started with angular js by
Getting started with angular jsGetting started with angular js
Getting started with angular jsMaurice De Beijer [MVP]
11.2K views21 slides
ASP.NET MVC 5 - EF 6 - VS2015 by
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015Hossein Zahed
3.4K views148 slides

More Related Content

What's hot

ASP .NET MVC - best practices by
ASP .NET MVC - best practicesASP .NET MVC - best practices
ASP .NET MVC - best practicesBohdan Pashkovskyi
391 views28 slides
The Magic Revealed: Four Real-World Examples of Using the Client Object Model... by
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...SPTechCon
3K views52 slides
Introduction to ASP.NET MVC by
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCLearnNowOnline
1.5K views112 slides
ASP .NET MVC by
ASP .NET MVC ASP .NET MVC
ASP .NET MVC eldorina
1K views13 slides
ASP.NET MVC for Begineers by
ASP.NET MVC for BegineersASP.NET MVC for Begineers
ASP.NET MVC for BegineersShravan Kumar Kasagoni
5.5K views26 slides
Knockout js by
Knockout jsKnockout js
Knockout jsshobokshi
1.6K views13 slides

What's hot(20)

The Magic Revealed: Four Real-World Examples of Using the Client Object Model... by SPTechCon
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
SPTechCon3K views
Introduction to ASP.NET MVC by LearnNowOnline
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
LearnNowOnline1.5K views
ASP .NET MVC by eldorina
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
eldorina1K views
Knockout js by shobokshi
Knockout jsKnockout js
Knockout js
shobokshi1.6K views
Principles of MVC for PHP Developers by Edureka!
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP Developers
Edureka!3.1K views
MVC Puree - Approaches to MVC with Umbraco by Andy Butland
MVC Puree - Approaches to MVC with UmbracoMVC Puree - Approaches to MVC with Umbraco
MVC Puree - Approaches to MVC with Umbraco
Andy Butland2.6K views
Angular JS, A dive to concepts by Abhishek Sur
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
Abhishek Sur523 views
Web Development with Delphi and React - ITDevCon 2016 by Marco Breveglieri
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
Marco Breveglieri5.5K views
ASP.net MVC Introduction Wikilogia (nov 2014) by Hatem Hamad
ASP.net MVC Introduction Wikilogia (nov 2014)ASP.net MVC Introduction Wikilogia (nov 2014)
ASP.net MVC Introduction Wikilogia (nov 2014)
Hatem Hamad591 views
Introduction to ASP.NET MVC by Joe Wilson
Introduction to ASP.NET MVC Introduction to ASP.NET MVC
Introduction to ASP.NET MVC
Joe Wilson725 views
MVC Demystified: Essence of Ruby on Rails by codeinmotion
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Rails
codeinmotion21.4K views
ASP.NET MVC 3 by Buu Nguyen
ASP.NET MVC 3ASP.NET MVC 3
ASP.NET MVC 3
Buu Nguyen6.2K views
The Web on Windows by Josh Lane
The Web on WindowsThe Web on Windows
The Web on Windows
Josh Lane461 views
HTML5: the new frontier of the web by Ivano Malavolta
HTML5: the new frontier of the webHTML5: the new frontier of the web
HTML5: the new frontier of the web
Ivano Malavolta2.4K views

Viewers also liked

Angular from a Different Angle by
Angular from a Different AngleAngular from a Different Angle
Angular from a Different AngleJeremy Likness
14.5K views31 slides
Advanced AngularJS Tips and Tricks by
Advanced AngularJS Tips and TricksAdvanced AngularJS Tips and Tricks
Advanced AngularJS Tips and TricksJeremy Likness
5.1K views20 slides
Let's Build an Angular App! by
Let's Build an Angular App!Let's Build an Angular App!
Let's Build an Angular App!Jeremy Likness
14.1K views33 slides
Angle Forward with TypeScript by
Angle Forward with TypeScriptAngle Forward with TypeScript
Angle Forward with TypeScriptJeremy Likness
3.2K views7 slides
C# Async/Await Explained by
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await ExplainedJeremy Likness
7.1K views34 slides
Back to the ng2 Future by
Back to the ng2 FutureBack to the ng2 Future
Back to the ng2 FutureJeremy Likness
6.2K views15 slides

Viewers also liked(7)

Angular from a Different Angle by Jeremy Likness
Angular from a Different AngleAngular from a Different Angle
Angular from a Different Angle
Jeremy Likness14.5K views
Advanced AngularJS Tips and Tricks by Jeremy Likness
Advanced AngularJS Tips and TricksAdvanced AngularJS Tips and Tricks
Advanced AngularJS Tips and Tricks
Jeremy Likness5.1K views
Let's Build an Angular App! by Jeremy Likness
Let's Build an Angular App!Let's Build an Angular App!
Let's Build an Angular App!
Jeremy Likness14.1K views
Angle Forward with TypeScript by Jeremy Likness
Angle Forward with TypeScriptAngle Forward with TypeScript
Angle Forward with TypeScript
Jeremy Likness3.2K views
Cross-Platform Agile DevOps with Visual Studio Team Services by Jeremy Likness
Cross-Platform Agile DevOps with Visual Studio Team ServicesCross-Platform Agile DevOps with Visual Studio Team Services
Cross-Platform Agile DevOps with Visual Studio Team Services
Jeremy Likness238 views

Similar to My XML is Alive! An Intro to XAML

No more Three Tier - A path to a better code for Cloud and Azure by
No more Three Tier - A path to a better code for Cloud and AzureNo more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and AzureMarco Parenzan
419 views70 slides
Introducing Oslo by
Introducing OsloIntroducing Oslo
Introducing OsloSuresh Veeragoni
290 views20 slides
Data modeling star schema by
Data modeling star schemaData modeling star schema
Data modeling star schemaSayed Ahmed
3.6K views36 slides
Be a database professional by
Be a database professionalBe a database professional
Be a database professionalSayed Ahmed
201 views36 slides
Be a database professional by
Be a database professionalBe a database professional
Be a database professionalSayed Ahmed
161 views36 slides
Silverlight Developer Introduction by
Silverlight   Developer IntroductionSilverlight   Developer Introduction
Silverlight Developer IntroductionTomy Ismail
232 views32 slides

Similar to My XML is Alive! An Intro to XAML(20)

No more Three Tier - A path to a better code for Cloud and Azure by Marco Parenzan
No more Three Tier - A path to a better code for Cloud and AzureNo more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and Azure
Marco Parenzan419 views
Data modeling star schema by Sayed Ahmed
Data modeling star schemaData modeling star schema
Data modeling star schema
Sayed Ahmed3.6K views
Be a database professional by Sayed Ahmed
Be a database professionalBe a database professional
Be a database professional
Sayed Ahmed201 views
Be a database professional by Sayed Ahmed
Be a database professionalBe a database professional
Be a database professional
Sayed Ahmed161 views
Silverlight Developer Introduction by Tomy Ismail
Silverlight   Developer IntroductionSilverlight   Developer Introduction
Silverlight Developer Introduction
Tomy Ismail232 views
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ... by Bill Buchan
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Bill Buchan470 views
MPhil Lecture of Data Vis for Presentation by Shawn Day
MPhil Lecture of Data Vis for PresentationMPhil Lecture of Data Vis for Presentation
MPhil Lecture of Data Vis for Presentation
Shawn Day818 views
Building appsinsilverlight4 part_1 by Dennis Perlot
Building appsinsilverlight4 part_1Building appsinsilverlight4 part_1
Building appsinsilverlight4 part_1
Dennis Perlot328 views
WinRT and the Web: Keeping Windows Store Apps Alive and Connected by Jeremy Likness
WinRT and the Web: Keeping Windows Store Apps Alive and ConnectedWinRT and the Web: Keeping Windows Store Apps Alive and Connected
WinRT and the Web: Keeping Windows Store Apps Alive and Connected
Jeremy Likness1.7K views
Azure vs AWS by Josh Lane
Azure vs AWSAzure vs AWS
Azure vs AWS
Josh Lane5.6K views
What Is The Zachman Framework by Mia Gordon
What Is The Zachman FrameworkWhat Is The Zachman Framework
What Is The Zachman Framework
Mia Gordon4 views
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)... by Karen Thompson
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Karen Thompson3 views
What is struts_en by techbed
What is struts_enWhat is struts_en
What is struts_en
techbed58.8K views
Elements of DDD with ASP.NET MVC & Entity Framework Code First by Enea Gabriel
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Enea Gabriel7.6K views
Drools & jBPM Info Sheet by Mark Proctor
Drools & jBPM Info SheetDrools & jBPM Info Sheet
Drools & jBPM Info Sheet
Mark Proctor5.9K views

Recently uploaded

Piloting & Scaling Successfully With Microsoft Viva by
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft VivaRichard Harbridge
13 views160 slides
The Forbidden VPN Secrets.pdf by
The Forbidden VPN Secrets.pdfThe Forbidden VPN Secrets.pdf
The Forbidden VPN Secrets.pdfMariam Shaba
20 views72 slides
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdfDr. Jimmy Schwarzkopf
24 views29 slides
Case Study Copenhagen Energy and Business Central.pdf by
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdfAitana
17 views3 slides
Kyo - Functional Scala 2023.pdf by
Kyo - Functional Scala 2023.pdfKyo - Functional Scala 2023.pdf
Kyo - Functional Scala 2023.pdfFlavio W. Brasil
418 views92 slides
Business Analyst Series 2023 - Week 3 Session 5 by
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5DianaGray10
345 views20 slides

Recently uploaded(20)

Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
The Forbidden VPN Secrets.pdf by Mariam Shaba
The Forbidden VPN Secrets.pdfThe Forbidden VPN Secrets.pdf
The Forbidden VPN Secrets.pdf
Mariam Shaba20 views
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana17 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10345 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2218 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab23 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely29 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson126 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi139 views
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe by Simone Puorto
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
Simone Puorto13 views

My XML is Alive! An Intro to XAML

  • 1. Consulting/Training My XML is Alive! (An Intro to XAML)
  • 2. Consulting/Training consulting Wintellect helps you build better software, faster, tackling the tough projects and solving the software and technology questions that help you transform your business.  Architecture, Analysis and Design  Full lifecycle software development  Debugging and Performance tuning  Database design and development training Wintellect's courses are written and taught by some of the biggest and most respected names in the Microsoft programming industry.  Learn from the best. Access the same training Microsoft’s developers enjoy  Real world knowledge and solutions on both current and cutting edge technologies  Flexibility in training options – onsite, virtual, on demand Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull out all the stops to help our customers achieve their goals through advanced software-based consulting and training solutions. who we are About Wintellect
  • 3. Consulting/Training  Imperative to Declare  XAML  Data-binding  Notify Property Change  Design-time Data  The Visual Tree  Value Converters  Dependency Objects and Properties  Attached Properties and Behaviors  The Visual State Manager  MVVM Agenda
  • 4. Consulting/Training  Imperative programming is the traditional approach to writing code. You just … write it.  Declarative programming lets you focus more on structure or tasks and leaves the solution to the compiler (or interpreter, or runtime).  Imperative is more testable and gives you more control over the implementation details.  Declarative tends to be more readable and accessible to non-developers (such as designers). Imperative to Declare
  • 5. Consulting/Training // imperative (long) var productNames = new List<string>(); foreach(var p in Products) { if (p.Price <= 9.99) { productNames.Add(p.ProductName); } } // a little of both (short with LINQ) var productNames = from p in Products where p.Price <= 9.99 select p.ProductName; // declarative (long with LINQ) var productNames = Products.Where(p => p.Price <= 9.99).Select(p => p.ProductName); Example of Imperative vs. Declarative How to filter the product How to project the product name What to filter What to project
  • 6. Consulting/Training <?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="myBindingConfiguration" closeTimeout="00:01:00" /> </basicHttpBinding> </bindings> <services> <service name="MyNamespace.myServiceType"> <endpoint address="myAddress" binding="basicHttpBinding" bindingConfiguration="myBindingConfiguration" contract="MyContract" /> </service> </services> </system.serviceModel> </configuration> WCF can be Declarative… What, what, and what
  • 7. Consulting/Training BasicHttpBinding myBinding = new BasicHttpBinding(); EndpointAddress myEndpoint = new EndpointAddress("myAddress"); ChannelFactory<MyContract> myChannelFactory = new ChannelFactory<MyContract>(myBinding, myEndpoint); MyContract wcfClient = myChannelFactory.CreateChannel(); …or WCF can be Imperative How, how, how …
  • 8. Consulting/Training <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>I Hereby Declare</title> <meta name="description" content="I Hereby Declare"> <meta name="author" content="Jeremy Likness"> <link rel="stylesheet" href="css/styles.css"> </head> <body> <h1>This is the Heading</h1> <p>Can you get a sense of the structure from this? </body> </html> HTML is Declarative…
  • 9. Consulting/Training <?xml version="1.0"> <note> <to>Jeremy Likness</to> <from>Me</from> <body>Do not forget to show the XML example.</body> </note> …and so is XML
  • 10. Consulting/Training  eXtensible Application Markup Language  Pronounced “Zammel” (rhymes with “Camel”)  An open specification by Microsoft  XAML *is* XML  Instantiates classes and initializes values and properties  Used in WPF, Silverlight (including Windows Phone apps), Windows Workflow Foundation, and the Windows Runtime  XML  CLR (or WinRT) that is language independent  The same XAML can be used whether you are writing your imperative code in C#, VB.NET, or even C++ XAML
  • 12. Consulting/Training  XAML instantiates classes  XAML populates properties  UI Elements can be declared with XAML  UI Elements have a special feature called “data- binding”  Data-binding can be used to view data  Anything that can be declared in XAML can be written with code! What Did We Learn?
  • 13. Consulting/Training var page = new Page(); var grid = new Grid(); page.Content = new Grid(); var textBlock = new TextBlock(); var binding = new Binding { Path = new PropertyPath("Result") }; textBlock.SetBinding(TextBlock.TextProperty, binding); grid.Children.Add(textBlock); grid.DataContext = new object(); // calculator here XAML  Code
  • 14. Consulting/Training <TextBlock Style="{StaticResource HeaderTextStyle}" Text="{Binding Path=Result}"/> Quick Decomposition Create an instance of the TextBlock WinRT component Set the Style property of the TextBlock Moustaches are for markup extensions. They will instantiate the “StaticResource” class and pass the “HeaderTextStyle” parameter This one uses a named parameter with the special Binding markup extension. Binding is what makes XAML magic for UI.
  • 18. Consulting/Training  Simple interface to implement on your class  Whenever you want data-binding to “know” about changes (typically whenever a property is updated) you raise an event with the property name  Empty property name means “all properties are suspect”  Also similar interface and events for collections (observable collections) Notify Property Change
  • 19. Consulting/Training  Very powerful – you don’t want to “design in the dark”  You can implement this several ways, including “design-aware classes”  Visual Studio 2013 has support for data files (such as JSON)  Specify a data source and type, or an instance and “is design-time creatable” Design-time Data
  • 22. Consulting/Training  Helps separate the data from the information (the raw “stuff” from the presentation)  Takes in one value, spits out another value  Works equally well on primitives and complex types  Typically one way (for presentation) however can be both ways in case you want to take user input and map it back to an internal instance  Avoid things like string-formatting, data preparation, etc. in your model, instead use the built-in XAML constructs to do this in the view Value Converters
  • 23. Consulting/Training  Provides the “dependency property system” designed to compute values of properties from multiple sources (XAML configuration, animations, styles, data-binding, etc.) and provide system notification when values have changed  Properties are registered with the system and exposes as CLR properties that pass information back and forth to the underlying object  Common base for most XAML UI elements – allows them to bind to each other, to data sources, etc.  Provides inheritance, i.e. “data context” can be set at a parent level and propagate to children Dependency Objects and Properties
  • 25. Consulting/Training  Used to extend functionality or apply a common behavior to existing elements  For example, an element doesn’t “know” about grid rows and columns, but attached properties extend elements to allow them to specify what cells to appear in when a grid is rendered  If you find you are performing a common operation (such as listening to text change events to update data-bindings) consider encapsulating in a behavior  Behaviors are independently testable and then reusable and can be applied across existing elements  Use dependency properties to save/recall values Attached Properties and Behaviors
  • 27. Consulting/Training  Again helps to separate the UI from the code logic  Declarative way to map states to their visual representation  Rich support for animations  Transitions to emphasize the shift between states  Orthogonal groups  Mutually exclusive states The Visual State Manager
  • 29. Consulting/Training  At the basic level means you have a class that exposes properties for data-binding and holds the state of the presentation  Commands are a special type of data-bound “action”  Plenty of libraries but WinRT XAML has plenty to support it “out of the box”  Don’t be afraid of code-behind when it relates to the UI (presentation) piece – after all, it is just an extension of the classes that are declared by XAML  Reuse across platforms (phone, Windows 8, etc.) Model-View-ViewModel
  • 30. Consulting/Training  Imperative to Declare  XAML  Data-binding  Notify Property Change  Design-time Data  The Visual Tree  Value Converters  Dependency Objects and Properties  Attached Properties and Behaviors  The Visual State Manager  MVVM Recap
  • 31. Consulting/Training Subscribers Enjoy  Expert Instructors  Quality Content  Practical Application  All Devices Wintellect’s On-Demand Video Training Solution Individuals | Businesses | Enterprise Organizations WintellectNOW.com Authors Enjoy  Royalty Income  Personal Branding  Free Library Access  Cross-Sell Opportunities Try It Free! Use Promo Code: LIKNESS-13

Editor's Notes

  1. Author Opportunity Passive incomeClear marketing commitments to help grow your personal brand and your coursesInternational presence &amp; exposureCross sell opportunities – instructor led classes, consulting opportunities, and conference speaking opportunitiesOpportunity to be the subject matter expert and to carve out a niche for yourself in this new businessAssociation with Wintellect