SlideShare a Scribd company logo
Custom Markup Extensions
Create re-usable, descriptive XAML elements
Andreas Kuntner
• Senior Frontend Dev @
• C# .NET Development
• Client, UI, Mobile development
• App and library publications
• Developer’s blog
http://www.mobilemotion.eu
Let’s start with some XAML code
<Rectangle>
<Rectangle.Fill>
<SolidColorBrush Color="#FF0000"/>
</Rectangle.Fill>
</Rectangle>
Dynamic XML macros
<Rectangle>
<Rectangle.Fill>
<SolidColorBrush Color="{Binding MyColor}"/>
</Rectangle.Fill>
</Rectangle>
Common Markup Extensions
• {Binding}
• {StaticResource}
• {DynamicResource}
• {x:Static}
• {x:Type}
• {x:Bind}
• etc.
Custom Markup Extensions
• Derive from MarkupExtension
• Naming convention: XyzEntension
• Usage:
<SomeElement
Attribute=“{Xyz Property1=Value,
Property2=Value}” />
Custom Markup Extensions
• Derive from MarkupExtension
• Naming convention: XyzEntension
• Usage:
<SomeElement
Attribute=“{Xyz Property1=Value,
Property2=Value}” />
• Flag return type:
[MarkupExtensionReturnType(typeof(string))]
• Flag default (single) parameter:
[ConstructorArgument(“parameter")]
XAML Services
• IServiceProvider: LineNumber, LinePosition
• IProvideValueTarget: TargetObject, TargetProperty
• IUriContext: BaseUri
• IRootObjectProvider: RootObject
• IXamlNameResolver: GetAllNamesAndValuesInScope()
• IXamlSchemaContextProvider: SchemaContext
Platform compatibility
+ WPF
+ (Silverligt 5 / Windows Phone Silverlight)
+ Xamarin.Forms
- WinRT
~ UWP
Xamarin.Forms Markup Extensions
• Implement the IMarkupExtension interface
• To flag return type, use
IMarkupExtension<T>
and
public T ProvideValue(IServiceProvider s)
Custom Markup Extensions vs. UWP
MarkupExtension class is not available, but:
• as a workaround for fetching resources etc., use
CustomXamlResourceLoader
• Override its GetResource method and retrieve:
• one parameter
• target object
• target property
• target property type
• Don’t forget to register your loader during App startup!
Samples
• <TextBlock Text=“{Localization Text1}” />
• <Grid Visibility=“{Binding Flag,
Converter={VisibilityConverter}” />
• <Button MouseOver=“{EventBinding MyCommand”>
touch me!
</Button>
• etc.
http://blog.mobilemotion.eu/

More Related Content

Similar to Custom Markup Extensions: Create re-usable, descriptive XAML elements

Microservice Automated Testing on Kubernetes
Microservice Automated Testing on KubernetesMicroservice Automated Testing on Kubernetes
Microservice Automated Testing on Kubernetes
Shane Galvin
 
Presentation wpf
Presentation wpfPresentation wpf
Presentation wpf
danishrafiq
 
Stream Application Development with Apache Kafka
Stream Application Development with Apache KafkaStream Application Development with Apache Kafka
Stream Application Development with Apache Kafka
Matthias J. Sax
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Jussi Pohjolainen
 
WEB DEVELOPMENT20CS41.pdf
WEB DEVELOPMENT20CS41.pdfWEB DEVELOPMENT20CS41.pdf
WEB DEVELOPMENT20CS41.pdf
DeepakMeena597272
 
Wpf-Xaml And Layout Basics
Wpf-Xaml And Layout BasicsWpf-Xaml And Layout Basics
Wpf-Xaml And Layout Basics
Robin Aggarwal
 
JSLab.Руслан Шевченко."JavaScript как платформа компиляции"
JSLab.Руслан Шевченко."JavaScript как платформа компиляции"JSLab.Руслан Шевченко."JavaScript как платформа компиляции"
JSLab.Руслан Шевченко."JavaScript как платформа компиляции"
GeeksLab Odessa
 
Jslab rssh: JS as language platform
Jslab rssh:  JS as language platformJslab rssh:  JS as language platform
Jslab rssh: JS as language platform
Ruslan Shevchenko
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
koppenolski
 
AWS CloudFormation under the Hood (DMG303) | AWS re:Invent 2013
AWS CloudFormation under the Hood (DMG303) | AWS re:Invent 2013AWS CloudFormation under the Hood (DMG303) | AWS re:Invent 2013
AWS CloudFormation under the Hood (DMG303) | AWS re:Invent 2013
Amazon Web Services
 
Flex 4 Overview
Flex 4 OverviewFlex 4 Overview
Flex 4 Overview
RJ Owen
 
Cassandra's Sweet Spot - an introduction to Apache Cassandra
Cassandra's Sweet Spot - an introduction to Apache CassandraCassandra's Sweet Spot - an introduction to Apache Cassandra
Cassandra's Sweet Spot - an introduction to Apache Cassandra
Dave Gardner
 
Non-Microsoft Technologies Which Microsoft is Embracing
Non-Microsoft Technologies Which Microsoft is EmbracingNon-Microsoft Technologies Which Microsoft is Embracing
Non-Microsoft Technologies Which Microsoft is Embracing
Elton Stoneman
 
Automate The Creation/Transformation of Infrastructure as Code Artifacts with...
Automate The Creation/Transformation of Infrastructure as Code Artifacts with...Automate The Creation/Transformation of Infrastructure as Code Artifacts with...
Automate The Creation/Transformation of Infrastructure as Code Artifacts with...
Konveyor Community
 
Simplify integrations-final-pdf
Simplify integrations-final-pdfSimplify integrations-final-pdf
Simplify integrations-final-pdf
Christian Posta
 
025444215.pptx
025444215.pptx025444215.pptx
025444215.pptx
RiyaJenner1
 
Microsoft (Silverlight)
Microsoft (Silverlight)Microsoft (Silverlight)
Microsoft (Silverlight)
Vinayak Hegde
 
Monkey Conf 2020: Xamarin Community Toolkit: More possibilities with Xamarin....
Monkey Conf 2020: Xamarin Community Toolkit: More possibilities with Xamarin....Monkey Conf 2020: Xamarin Community Toolkit: More possibilities with Xamarin....
Monkey Conf 2020: Xamarin Community Toolkit: More possibilities with Xamarin....
Javier Suárez Ruiz
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
Reagan Hwang
 
Overview of PHP and MYSQL
Overview of PHP and MYSQLOverview of PHP and MYSQL
Overview of PHP and MYSQL
Deblina Chowdhury
 

Similar to Custom Markup Extensions: Create re-usable, descriptive XAML elements (20)

Microservice Automated Testing on Kubernetes
Microservice Automated Testing on KubernetesMicroservice Automated Testing on Kubernetes
Microservice Automated Testing on Kubernetes
 
Presentation wpf
Presentation wpfPresentation wpf
Presentation wpf
 
Stream Application Development with Apache Kafka
Stream Application Development with Apache KafkaStream Application Development with Apache Kafka
Stream Application Development with Apache Kafka
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
WEB DEVELOPMENT20CS41.pdf
WEB DEVELOPMENT20CS41.pdfWEB DEVELOPMENT20CS41.pdf
WEB DEVELOPMENT20CS41.pdf
 
Wpf-Xaml And Layout Basics
Wpf-Xaml And Layout BasicsWpf-Xaml And Layout Basics
Wpf-Xaml And Layout Basics
 
JSLab.Руслан Шевченко."JavaScript как платформа компиляции"
JSLab.Руслан Шевченко."JavaScript как платформа компиляции"JSLab.Руслан Шевченко."JavaScript как платформа компиляции"
JSLab.Руслан Шевченко."JavaScript как платформа компиляции"
 
Jslab rssh: JS as language platform
Jslab rssh:  JS as language platformJslab rssh:  JS as language platform
Jslab rssh: JS as language platform
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
 
AWS CloudFormation under the Hood (DMG303) | AWS re:Invent 2013
AWS CloudFormation under the Hood (DMG303) | AWS re:Invent 2013AWS CloudFormation under the Hood (DMG303) | AWS re:Invent 2013
AWS CloudFormation under the Hood (DMG303) | AWS re:Invent 2013
 
Flex 4 Overview
Flex 4 OverviewFlex 4 Overview
Flex 4 Overview
 
Cassandra's Sweet Spot - an introduction to Apache Cassandra
Cassandra's Sweet Spot - an introduction to Apache CassandraCassandra's Sweet Spot - an introduction to Apache Cassandra
Cassandra's Sweet Spot - an introduction to Apache Cassandra
 
Non-Microsoft Technologies Which Microsoft is Embracing
Non-Microsoft Technologies Which Microsoft is EmbracingNon-Microsoft Technologies Which Microsoft is Embracing
Non-Microsoft Technologies Which Microsoft is Embracing
 
Automate The Creation/Transformation of Infrastructure as Code Artifacts with...
Automate The Creation/Transformation of Infrastructure as Code Artifacts with...Automate The Creation/Transformation of Infrastructure as Code Artifacts with...
Automate The Creation/Transformation of Infrastructure as Code Artifacts with...
 
Simplify integrations-final-pdf
Simplify integrations-final-pdfSimplify integrations-final-pdf
Simplify integrations-final-pdf
 
025444215.pptx
025444215.pptx025444215.pptx
025444215.pptx
 
Microsoft (Silverlight)
Microsoft (Silverlight)Microsoft (Silverlight)
Microsoft (Silverlight)
 
Monkey Conf 2020: Xamarin Community Toolkit: More possibilities with Xamarin....
Monkey Conf 2020: Xamarin Community Toolkit: More possibilities with Xamarin....Monkey Conf 2020: Xamarin Community Toolkit: More possibilities with Xamarin....
Monkey Conf 2020: Xamarin Community Toolkit: More possibilities with Xamarin....
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
 
Overview of PHP and MYSQL
Overview of PHP and MYSQLOverview of PHP and MYSQL
Overview of PHP and MYSQL
 

Recently uploaded

Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
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
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
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
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
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
 

Recently uploaded (20)

Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
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
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
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
 

Custom Markup Extensions: Create re-usable, descriptive XAML elements

  • 1. Custom Markup Extensions Create re-usable, descriptive XAML elements
  • 2. Andreas Kuntner • Senior Frontend Dev @ • C# .NET Development • Client, UI, Mobile development • App and library publications • Developer’s blog http://www.mobilemotion.eu
  • 3. Let’s start with some XAML code <Rectangle> <Rectangle.Fill> <SolidColorBrush Color="#FF0000"/> </Rectangle.Fill> </Rectangle>
  • 4. Dynamic XML macros <Rectangle> <Rectangle.Fill> <SolidColorBrush Color="{Binding MyColor}"/> </Rectangle.Fill> </Rectangle>
  • 5. Common Markup Extensions • {Binding} • {StaticResource} • {DynamicResource} • {x:Static} • {x:Type} • {x:Bind} • etc.
  • 6. Custom Markup Extensions • Derive from MarkupExtension • Naming convention: XyzEntension • Usage: <SomeElement Attribute=“{Xyz Property1=Value, Property2=Value}” />
  • 7. Custom Markup Extensions • Derive from MarkupExtension • Naming convention: XyzEntension • Usage: <SomeElement Attribute=“{Xyz Property1=Value, Property2=Value}” /> • Flag return type: [MarkupExtensionReturnType(typeof(string))] • Flag default (single) parameter: [ConstructorArgument(“parameter")]
  • 8. XAML Services • IServiceProvider: LineNumber, LinePosition • IProvideValueTarget: TargetObject, TargetProperty • IUriContext: BaseUri • IRootObjectProvider: RootObject • IXamlNameResolver: GetAllNamesAndValuesInScope() • IXamlSchemaContextProvider: SchemaContext
  • 9. Platform compatibility + WPF + (Silverligt 5 / Windows Phone Silverlight) + Xamarin.Forms - WinRT ~ UWP
  • 10. Xamarin.Forms Markup Extensions • Implement the IMarkupExtension interface • To flag return type, use IMarkupExtension<T> and public T ProvideValue(IServiceProvider s)
  • 11. Custom Markup Extensions vs. UWP MarkupExtension class is not available, but: • as a workaround for fetching resources etc., use CustomXamlResourceLoader • Override its GetResource method and retrieve: • one parameter • target object • target property • target property type • Don’t forget to register your loader during App startup!
  • 12. Samples • <TextBlock Text=“{Localization Text1}” /> • <Grid Visibility=“{Binding Flag, Converter={VisibilityConverter}” /> • <Button MouseOver=“{EventBinding MyCommand”> touch me! </Button> • etc.