SlideShare ist ein Scribd-Unternehmen logo
1 von 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.

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
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
 
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
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
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
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 

Kürzlich hochgeladen (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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...
 
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
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
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
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 

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.