SlideShare a Scribd company logo
1 of 13
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 Create reusable XAML elements with custom markup extensions

Microservice Automated Testing on Kubernetes
Microservice Automated Testing on KubernetesMicroservice Automated Testing on Kubernetes
Microservice Automated Testing on KubernetesShane Galvin
 
Presentation wpf
Presentation wpfPresentation wpf
Presentation wpfdanishrafiq
 
Stream Application Development with Apache Kafka
Stream Application Development with Apache KafkaStream Application Development with Apache Kafka
Stream Application Development with Apache KafkaMatthias J. Sax
 
Wpf-Xaml And Layout Basics
Wpf-Xaml And Layout BasicsWpf-Xaml And Layout Basics
Wpf-Xaml And Layout BasicsRobin 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 platformRuslan Shevchenko
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScriptkoppenolski
 
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 2013Amazon Web Services
 
Flex 4 Overview
Flex 4 OverviewFlex 4 Overview
Flex 4 OverviewRJ 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 CassandraDave 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 EmbracingElton 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-pdfChristian Posta
 
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
 

Similar to Create reusable XAML elements with custom markup extensions (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

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
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 Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
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.
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
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
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
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
 
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
 
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 Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
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
 
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
 
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
 
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
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Recently uploaded (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
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 Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
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...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
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...
 
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
 
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 🔝✔️✔️
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
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
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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
 
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
 
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
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Create reusable XAML elements with custom markup extensions

  • 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.