SlideShare une entreprise Scribd logo
1  sur  26
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.

Contenu connexe

Similaire à 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 UpdateFons 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 TemplatesMohammad Shaker
 
Building iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360FlexBuilding iPad apps with Flex - 360Flex
Building iPad apps with Flex - 360Flexdanielwanja
 
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 8netmind
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its featuresAbhishek Sur
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVMAbhishek Sur
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with StripesSamuel Santos
 
Working with Javascript in Rails
Working with Javascript in RailsWorking with Javascript in Rails
Working with Javascript in RailsSeungkyun 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 BatchEberhard Wolff
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJSDavid Parsons
 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014Dariusz Kalbarczyk
 
Comparing xaml and html
Comparing xaml and htmlComparing xaml and html
Comparing xaml and htmlKevin DeRudder
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & AnimationNguyen Tuan
 
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
 

Similaire à 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 sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
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
 
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
 

Plus de Senthamil Selvan

Get started azure- Azure Mobile Services
Get started azure- Azure Mobile ServicesGet started azure- Azure Mobile Services
Get started azure- Azure Mobile ServicesSenthamil 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 & jsSenthamil Selvan
 
Univeral App using O365 API
Univeral App using O365 APIUniveral App using O365 API
Univeral App using O365 APISenthamil Selvan
 
SharePoint Farm Setup On Azure
SharePoint Farm Setup On AzureSharePoint Farm Setup On Azure
SharePoint Farm Setup On AzureSenthamil Selvan
 
Windows 8.1 Start Screen Features
Windows 8.1 Start Screen FeaturesWindows 8.1 Start Screen Features
Windows 8.1 Start Screen FeaturesSenthamil Selvan
 
jQuery programming with visual web part
jQuery programming with visual web partjQuery programming with visual web part
jQuery programming with visual web partSenthamil Selvan
 
Share point guidance package
Share point guidance packageShare point guidance package
Share point guidance packageSenthamil Selvan
 

Plus de 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
 

Dernier

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 

Dernier (20)

Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 

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.