From the course: Microsoft XAML: 3 Type Converters and Resources

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Create a custom markup extension

Create a custom markup extension

From the course: Microsoft XAML: 3 Type Converters and Resources

Start my 1-month free trial

Create a custom markup extension

- [Instructor] To create a custom markup extension, add a class to your project, then derive from markup extension. Give your class a good name, my extension is a random number generator so I decided to call it roll the dice, and I'm using the Microsoft naming convention which is to put the word extension on the end of my class. So the fully qualified name of my class is roll the dice extension. When I use it in my zaml I only need to use this part of the name though, roll the dice. When you use a markup extension in zaml you typically pass one or more parameters into the markup extension, then your code does the work, the custom markup extension does some work and returns a value that's then used as the property value in the zaml. The key to doing that is to override this method, provide value. And this can return anything. This is returned of type object, I'm going to return a string. If you want to specify a particular data type that you return other than object, you come up to…

Contents