SlideShare a Scribd company logo
XAML PROGRAMMING
Windows Phone User Group, Singapore. 26 April 2014
TOPICS
• Intro to XAML
• XAML UI Elements
• Controls
• Data Binding
• MVVM
EXTENSIBLE APPLICATION MARKUP
LANGUAGESerialization and Initialization format
<Activity x:TypeArguments="x:Int32"
x:Class="Add"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" >
<x:Members>
<x:Property Name="Operand1" Type="InArgument(x:Int32)" />
< x:Property Name="Operand2" Type="InArgument(x:Int32)" />
</x:Members>
<Sequence>
<Assign x:TypeArguments="x:Int32" Value="[Operand1 + Operand2]">
<Assign.To>
<OutArgument x:TypeArguments="x:Int32">
<ArgumentReference x:TypeArguments="x:Int32"
ArgumentName="Result"/>
</OutArgument>
</Assign.To>
</Assign>
</Sequence>
</Activity>
XAML - USER INTERFACE
Declarative
Toolable
Recommended
<Page
x:Class="App12.MainPage"…>
<Grid>
<Grid.Resources>
<Style x:Key="PinkButton" TargetType="Button">
<Setter Property="Background" Value="Pink" />
</Style>
</Grid.Resources>
<Button
x:Name="myButton"
Style="{StaticResource PinkButton}"
Content="{Binding data.buttonName}"
Click="OnButtonClick"
Width="300"
Margin="250"
VerticalAlignment="Stretch">
</Button>
</Grid>
</Page>
DECLARATIVE
Button b = new Button();
b.Width = 100;
b.Height = 50;
b.Content = "Click Me!";
b.Background =
new SolidColorBrush( Colors.Green);
<Button Content="Click Me!" Width="100"
Height="50" Background="Green“ />
UI ELEMENTS
Brushes, Shapes, Styles &Properties
STYLES
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:phone="clr-
namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="RecipeTitle" TargetType="TextBlock">
<Setter Property="Foreground" Value="Orange" />
<Setter Property="FontSize" Value="24"/>
</Style>
</ResourceDictionary>
DEPENDENCY PROPERTIES
• Special properties that power most of the presentation engine features
- Data Binding
- Styling
- Attached Properties
- Animation
- Property Invalidation
- Property Inheritance
- Default Values
- Sparse Storage
DEFINING DEPENDENCY
PROPERTIES• Inherit from DependencyObject
• Call DependencyObject.Register
• Create standard property
public static readonly DependencyProperty RadiusProperty =
DependencyProperty.Register("Radius", typeof(double), typeof(CarouselPanel),
new PropertyMetadata(200.0, new
PropertyChangedCallback(CarouselPanel.RadiusChanged)));
// optional but convenient
public double Radius
{
get { return (double)this.GetValue(RadiusProperty); }
set
{
this.SetValue(RadiusProperty, value);
}
}
ATTACHED PROPERTIES
• Inherit from DependencyObject
• Call DependencyProperty.RegisterAttach
• Create two static methods Getnnn/Setnnn
public static readonly DependencyProperty RowProperty =
DependencyProperty.RegisterAttached("Row", typeof(int), typeof(Grid),
new PropertyMetadata(0, new PropertyChangedCallback(OnRowChanged)));
public static void SetRow(DependencyObject obj, int value)
{
obj.SetValue(RowProperty, value);
}
public static int GetRow(DependencyObject obj )
{
return (int) obj.GetValue(RowProperty);
}
LAYOUTS
Control Layouts
PROPERTIES AFFECTING LAYOUT
• Width/Height
• HorizontalAlignment/VerticalAlignment
• Margin
• Padding
• Visibility
MARGIN• Space outside edges of an element
<StackPanel Orientation="Horizontal" Height="200" Background="AliceBlue">
<Rectangle Width="100" Height="100" Fill="Yellow" />
<Rectangle Width="100" Height="100" Fill="Green"/>
<Rectangle Width="100" Height="100" Fill="Yellow" Margin="30"/>
<Rectangle Width="100" Height="100" Fill="Green" Margin="50"/>
<Rectangle Width="100" Height="100" Fill="Yellow" Margin="80"/>
</StackPanel>
PADDING• Space inside edges of an element
<Border Width="300" Height="300" Background="Yellow" Padding="40“ >
<Rectangle Fill="Red" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</Border>
<Border Width="300" Height="300" Background="Yellow" Padding="100,5" Margin="449,112,617,356">
<Rectangle Fill="Red" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
</Border>
DATA BINDING
Declarative
DATA BINDING SCENARIOS AND
BENEFITS
Connects UI to data
• When data values change, UI updates
• If two-way: when user provides input, the data is updated too
Decreases code
Enables templating
COMPONENTS OF UI DATA
BINDING• A Binding consists of 4 components:
1. Source
2. Source path
3. Target dependency object
4. Target dependency property
Binding Target Binding Source
Object
Property
Dependency Object
Dependency Property
Binding Object
BINDING COMPONENTS IN XAML
1. Source
2. Source path
3. Target dependency object
4. Target dependency property
<TextBox IsEnabled="{Binding ElementName=MyCheckBox,Path=IsChecked}"/>
Target Dependency Property Source Path
Target Dependency Object
Source
BINDING TO NON-DPS
• Any public property on a CLR object will do
• Simple properties only read once by default
• Can update manually
• Updates occur only if notifications available
• INotifyPropertyChanged
INOTIFYPROPERTYCHANGED
• Defines the PropertyChanged event
• Of type PropertyChangedEventHandler
CONVERTERS
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object
parameter, string language)
{
bool val = (bool) value ;
return ( val ?
Visibility.Visible : Visibility.Collapsed) ;
}
public object ConvertBack(object value, Type targetType,
object parameter, string language)
{
var vis = (Visibility)value;
return vis == Visibility.Visible;
}
}
DATATEMPLATE & CONTENT
MODEL
• Some controls house content:
• ContentControl: Contains a single item
• ItemsControl: Contains a collection of items
• More generally:
• Anything with a ContentPresenter
• Enables use of a DataTemplate
MVVM
Model-View-ViewModel
Presentation Model
(ViewModel)
MVVM
Model View
The relationships
View
ViewModel
DataBinding Commands Services
Messages
Model
BENEFITS
• During the development process, developers and designers can work more
independently and concurrently on their components. The designers can
concentrate on the view, and if they are using Expression Blend, they can easily
generate sample data to work with, while the developers can work on the view
model and model components.
• The developers can create unit tests for the view model and the model without
using the view. The unit tests for the view model can exercise exactly the same
functionality as used by the view.
• It is easy to redesign the UI of the application without touching the code because
the view is implemented entirely in XAML. A new version of the view should work with
the existing view model.
• If there is an existing implementation of the model that encapsulates existing
business logic, it may be difficult or risky to change. In this scenario, the view model
acts as an adapter for the model classes and enables you to avoid making any
major changes to the model code.

More Related Content

Similar to Xaml programming

New XAML/UWP features in Windows 10 Fall Creators Update
New XAML/UWP features in Windows 10 Fall Creators UpdateNew XAML/UWP features in Windows 10 Fall Creators Update
New XAML/UWP features in Windows 10 Fall Creators Update
Fons Sonnemans
 
WPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and TemplatesWPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and Templates
Mohammad Shaker
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
Flavius-Radu Demian
 
Building iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360FlexBuilding iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360Flex
danielwanja
 
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
Abhishek Sur
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
Abhishek Sur
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with Stripes
Samuel Santos
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
Chandrasekar G
 
Working with Javascript in Rails
Working with Javascript in RailsWorking with Javascript in Rails
Working with Javascript in Rails
Seungkyun Nam
 
Spring Web Service, Spring Integration and Spring Batch
Spring Web Service, Spring Integration and Spring BatchSpring Web Service, Spring Integration and Spring Batch
Spring Web Service, Spring Integration and Spring Batch
Eberhard Wolff
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
David Parsons
 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014
Dariusz Kalbarczyk
 
Comparing xaml and html
Comparing xaml and htmlComparing xaml and html
Comparing xaml and html
Kevin DeRudder
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation
Nguyen Tuan
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Test driven development (java script & mivascript)
Test driven development (java script & mivascript)Test driven development (java script & mivascript)
Test driven development (java script & mivascript)
Miva
 
Asp.NET MVC
Asp.NET MVCAsp.NET MVC
Asp.NET MVC
vrluckyin
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
www.netgains.org
 

Similar to Xaml programming (20)

New XAML/UWP features in Windows 10 Fall Creators Update
New XAML/UWP features in Windows 10 Fall Creators UpdateNew XAML/UWP features in Windows 10 Fall Creators Update
New XAML/UWP features in Windows 10 Fall Creators Update
 
WPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and TemplatesWPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and Templates
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
 
Building iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360FlexBuilding iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360Flex
 
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with Stripes
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
 
Working with Javascript in Rails
Working with Javascript in RailsWorking with Javascript in Rails
Working with Javascript in Rails
 
Spring Web Service, Spring Integration and Spring Batch
Spring Web Service, Spring Integration and Spring BatchSpring Web Service, Spring Integration and Spring Batch
Spring Web Service, Spring Integration and Spring Batch
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014
 
Comparing xaml and html
Comparing xaml and htmlComparing xaml and html
Comparing xaml and html
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
Test driven development (java script & mivascript)
Test driven development (java script & mivascript)Test driven development (java script & mivascript)
Test driven development (java script & mivascript)
 
Asp.NET MVC
Asp.NET MVCAsp.NET MVC
Asp.NET MVC
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
 

More from Senthamil Selvan

AR/MR HoloLens
AR/MR HoloLensAR/MR HoloLens
AR/MR HoloLens
Senthamil Selvan
 
Get started azure- Azure Mobile Services
Get started azure- Azure Mobile ServicesGet started azure- Azure Mobile Services
Get started azure- Azure Mobile Services
Senthamil Selvan
 
Developing advanced universal apps using html & js
Developing advanced universal apps using html & jsDeveloping advanced universal apps using html & js
Developing advanced universal apps using html & js
Senthamil Selvan
 
Univeral App using O365 API
Univeral App using O365 APIUniveral App using O365 API
Univeral App using O365 API
Senthamil Selvan
 
Product centric site
Product centric siteProduct centric site
Product centric site
Senthamil Selvan
 
Building universal app
Building universal appBuilding universal app
Building universal app
Senthamil Selvan
 
SharePoint Farm Setup On Azure
SharePoint Farm Setup On AzureSharePoint Farm Setup On Azure
SharePoint Farm Setup On Azure
Senthamil Selvan
 
Azure Websites
Azure WebsitesAzure Websites
Azure Websites
Senthamil Selvan
 
Windows 8.1 Start Screen Features
Windows 8.1 Start Screen FeaturesWindows 8.1 Start Screen Features
Windows 8.1 Start Screen Features
Senthamil Selvan
 
jQuery programming with visual web part
jQuery programming with visual web partjQuery programming with visual web part
jQuery programming with visual web part
Senthamil Selvan
 
Surface presentation
Surface presentationSurface presentation
Surface presentation
Senthamil Selvan
 
Share point 2010 features
Share point 2010 featuresShare point 2010 features
Share point 2010 features
Senthamil Selvan
 
Silverlight 4
Silverlight 4Silverlight 4
Silverlight 4
Senthamil Selvan
 
Share point guidance package
Share point guidance packageShare point guidance package
Share point guidance package
Senthamil Selvan
 
ASP.NET MVC 4.0
ASP.NET MVC 4.0ASP.NET MVC 4.0
ASP.NET MVC 4.0
Senthamil Selvan
 

More from Senthamil Selvan (15)

AR/MR HoloLens
AR/MR HoloLensAR/MR HoloLens
AR/MR HoloLens
 
Get started azure- Azure Mobile Services
Get started azure- Azure Mobile ServicesGet started azure- Azure Mobile Services
Get started azure- Azure Mobile Services
 
Developing advanced universal apps using html & js
Developing advanced universal apps using html & jsDeveloping advanced universal apps using html & js
Developing advanced universal apps using html & js
 
Univeral App using O365 API
Univeral App using O365 APIUniveral App using O365 API
Univeral App using O365 API
 
Product centric site
Product centric siteProduct centric site
Product centric site
 
Building universal app
Building universal appBuilding universal app
Building universal app
 
SharePoint Farm Setup On Azure
SharePoint Farm Setup On AzureSharePoint Farm Setup On Azure
SharePoint Farm Setup On Azure
 
Azure Websites
Azure WebsitesAzure Websites
Azure Websites
 
Windows 8.1 Start Screen Features
Windows 8.1 Start Screen FeaturesWindows 8.1 Start Screen Features
Windows 8.1 Start Screen Features
 
jQuery programming with visual web part
jQuery programming with visual web partjQuery programming with visual web part
jQuery programming with visual web part
 
Surface presentation
Surface presentationSurface presentation
Surface presentation
 
Share point 2010 features
Share point 2010 featuresShare point 2010 features
Share point 2010 features
 
Silverlight 4
Silverlight 4Silverlight 4
Silverlight 4
 
Share point guidance package
Share point guidance packageShare point guidance package
Share point guidance package
 
ASP.NET MVC 4.0
ASP.NET MVC 4.0ASP.NET MVC 4.0
ASP.NET MVC 4.0
 

Recently uploaded

Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
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 Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
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
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 

Recently uploaded (20)

Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 

Xaml programming

  • 1. XAML PROGRAMMING Windows Phone User Group, Singapore. 26 April 2014
  • 2. TOPICS • Intro to XAML • XAML UI Elements • Controls • Data Binding • MVVM
  • 3. EXTENSIBLE APPLICATION MARKUP LANGUAGESerialization and Initialization format <Activity x:TypeArguments="x:Int32" x:Class="Add" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" > <x:Members> <x:Property Name="Operand1" Type="InArgument(x:Int32)" /> < x:Property Name="Operand2" Type="InArgument(x:Int32)" /> </x:Members> <Sequence> <Assign x:TypeArguments="x:Int32" Value="[Operand1 + Operand2]"> <Assign.To> <OutArgument x:TypeArguments="x:Int32"> <ArgumentReference x:TypeArguments="x:Int32" ArgumentName="Result"/> </OutArgument> </Assign.To> </Assign> </Sequence> </Activity>
  • 4. XAML - USER INTERFACE Declarative Toolable Recommended <Page x:Class="App12.MainPage"…> <Grid> <Grid.Resources> <Style x:Key="PinkButton" TargetType="Button"> <Setter Property="Background" Value="Pink" /> </Style> </Grid.Resources> <Button x:Name="myButton" Style="{StaticResource PinkButton}" Content="{Binding data.buttonName}" Click="OnButtonClick" Width="300" Margin="250" VerticalAlignment="Stretch"> </Button> </Grid> </Page>
  • 5. DECLARATIVE Button b = new Button(); b.Width = 100; b.Height = 50; b.Content = "Click Me!"; b.Background = new SolidColorBrush( Colors.Green); <Button Content="Click Me!" Width="100" Height="50" Background="Green“ />
  • 6. UI ELEMENTS Brushes, Shapes, Styles &Properties
  • 8. DEPENDENCY PROPERTIES • Special properties that power most of the presentation engine features - Data Binding - Styling - Attached Properties - Animation - Property Invalidation - Property Inheritance - Default Values - Sparse Storage
  • 9. DEFINING DEPENDENCY PROPERTIES• Inherit from DependencyObject • Call DependencyObject.Register • Create standard property public static readonly DependencyProperty RadiusProperty = DependencyProperty.Register("Radius", typeof(double), typeof(CarouselPanel), new PropertyMetadata(200.0, new PropertyChangedCallback(CarouselPanel.RadiusChanged))); // optional but convenient public double Radius { get { return (double)this.GetValue(RadiusProperty); } set { this.SetValue(RadiusProperty, value); } }
  • 10. ATTACHED PROPERTIES • Inherit from DependencyObject • Call DependencyProperty.RegisterAttach • Create two static methods Getnnn/Setnnn public static readonly DependencyProperty RowProperty = DependencyProperty.RegisterAttached("Row", typeof(int), typeof(Grid), new PropertyMetadata(0, new PropertyChangedCallback(OnRowChanged))); public static void SetRow(DependencyObject obj, int value) { obj.SetValue(RowProperty, value); } public static int GetRow(DependencyObject obj ) { return (int) obj.GetValue(RowProperty); }
  • 12. PROPERTIES AFFECTING LAYOUT • Width/Height • HorizontalAlignment/VerticalAlignment • Margin • Padding • Visibility
  • 13. MARGIN• Space outside edges of an element <StackPanel Orientation="Horizontal" Height="200" Background="AliceBlue"> <Rectangle Width="100" Height="100" Fill="Yellow" /> <Rectangle Width="100" Height="100" Fill="Green"/> <Rectangle Width="100" Height="100" Fill="Yellow" Margin="30"/> <Rectangle Width="100" Height="100" Fill="Green" Margin="50"/> <Rectangle Width="100" Height="100" Fill="Yellow" Margin="80"/> </StackPanel>
  • 14. PADDING• Space inside edges of an element <Border Width="300" Height="300" Background="Yellow" Padding="40“ > <Rectangle Fill="Red" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" /> </Border> <Border Width="300" Height="300" Background="Yellow" Padding="100,5" Margin="449,112,617,356"> <Rectangle Fill="Red" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/> </Border>
  • 16. DATA BINDING SCENARIOS AND BENEFITS Connects UI to data • When data values change, UI updates • If two-way: when user provides input, the data is updated too Decreases code Enables templating
  • 17. COMPONENTS OF UI DATA BINDING• A Binding consists of 4 components: 1. Source 2. Source path 3. Target dependency object 4. Target dependency property Binding Target Binding Source Object Property Dependency Object Dependency Property Binding Object
  • 18. BINDING COMPONENTS IN XAML 1. Source 2. Source path 3. Target dependency object 4. Target dependency property <TextBox IsEnabled="{Binding ElementName=MyCheckBox,Path=IsChecked}"/> Target Dependency Property Source Path Target Dependency Object Source
  • 19. BINDING TO NON-DPS • Any public property on a CLR object will do • Simple properties only read once by default • Can update manually • Updates occur only if notifications available • INotifyPropertyChanged
  • 20. INOTIFYPROPERTYCHANGED • Defines the PropertyChanged event • Of type PropertyChangedEventHandler
  • 21. CONVERTERS public class BoolToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { bool val = (bool) value ; return ( val ? Visibility.Visible : Visibility.Collapsed) ; } public object ConvertBack(object value, Type targetType, object parameter, string language) { var vis = (Visibility)value; return vis == Visibility.Visible; } }
  • 22. DATATEMPLATE & CONTENT MODEL • Some controls house content: • ContentControl: Contains a single item • ItemsControl: Contains a collection of items • More generally: • Anything with a ContentPresenter • Enables use of a DataTemplate
  • 26. BENEFITS • During the development process, developers and designers can work more independently and concurrently on their components. The designers can concentrate on the view, and if they are using Expression Blend, they can easily generate sample data to work with, while the developers can work on the view model and model components. • The developers can create unit tests for the view model and the model without using the view. The unit tests for the view model can exercise exactly the same functionality as used by the view. • It is easy to redesign the UI of the application without touching the code because the view is implemented entirely in XAML. A new version of the view should work with the existing view model. • If there is an existing implementation of the model that encapsulates existing business logic, it may be difficult or risky to change. In this scenario, the view model acts as an adapter for the model classes and enables you to avoid making any major changes to the model code.