Custom MarkupExtension in UWP
Asked Answered
I

1

4

I would like to create my own MarkupExtension (like Binding, TemplateBinding...)

How can I do it for Universal Apps like I did in WPF?

Immitigable answered 20/12, 2016 at 15:2 Comment(4)
Did you see this?Undergo
No, I didn't. Already voted. Thank you!Immitigable
Congratulations, you got it.Wollastonite
learn.microsoft.com/en-us/uwp/api/…Hamitic
G
5

I has a sad, but no. UWP doesn't currently support custom markup extensions.

In some cases you can work around this by using bindings and converters. For example, to use a resource string (not using x:Uid), I have a converter that doesn't actually need a value, only a parameter (the resource id).

For example, I might bind as follows:

<TextBlock
    Text="{x:Bind Language, Mode=OneWay, Converter={StaticResource Localize}, ConverterParameter=MyResourceId}"
/>

(This binding doesn't need a path, but I bind to Language anyway, which allows switching languages on the fly.)

More about the LocalizeConverter here.

But anyway. If I'd been doing WPF, this would have been a markup extension. Binding itself is, of course, a markup extension, so as long as you can work within its constraints, it is a possible workaround.

EDIT

I just want to highlight the link Clemens gave in his comment to the OP:

https://wpdev.uservoice.com/forums/110705-universal-windows-platform/suggestions/7232264-add-markup-extensions-to-and-improve-winrt-xaml

UPDATE

There is now limited support for custom markup extensions! (Hat tip to Michael Hawker's comment.)

Gable answered 20/12, 2016 at 15:24 Comment(1)
There's some supported subset of them now, see this answer: #47157282.Alert

© 2022 - 2024 — McMap. All rights reserved.