Custom MarkupExtension in UWP

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

How can I do this for universal applications like in WPF?

+3
source share
1 answer

I'm sad, but no. UWP does not currently support custom markup extensions.

In some cases, you can get around this using bindings and converters. For example, to use a resource string (without using x:Uid ), I have a converter that actually does not need a value, but only a parameter (resource identifier).

For example, I could communicate as follows:

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

(This binding does not need a path, but I get attached to Language anyway, which allows me to switch languages ​​on the fly.)

Read more about LocalizeConverter here .

But still. If I were doing WPF, this would be a markup extension. Binding itself is, of course, a markup extension, so while you can work within your limits, this is a possible workaround.

EDIT

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

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

UPDATE

There is currently limited support for custom markup extensions ! (Quote about Michael Hawker hat).

+4
source

Source: https://habr.com/ru/post/1013341/


All Articles