I would like to create my own MarkupExtension
(like Binding
, TemplateBinding
...)
How can I do it for Universal Apps like I did in WPF?
I would like to create my own MarkupExtension
(like Binding
, TemplateBinding
...)
How can I do it for Universal Apps like I did in WPF?
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:
UPDATE
There is now limited support for custom markup extensions! (Hat tip to Michael Hawker's comment.)
© 2022 - 2024 — McMap. All rights reserved.