Use Binding
.
<CalendarDatePicker
DateFormat="{x:Bind Format, Mode=OneWay}"
Date="{Binding StartDate, Converter={StaticResource DateToStringConverter}, Mode=TwoWay}"
/>
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have tried to create my own templated control that should work on x:Bind. By reading the offical document, I have created a code-behind Generic.xaml.cs file and referred it in App.xaml. When I use a converter inside my control, then it throws null pointer exception from the auto generated file of Generic.xaml.
Please refer the following repo for the full code.
Use Binding
.
<CalendarDatePicker
DateFormat="{x:Bind Format, Mode=OneWay}"
Date="{Binding StartDate, Converter={StaticResource DateToStringConverter}, Mode=TwoWay}"
/>
- Is there no other way to use {x:bind} with Converters?
It's not mentioned in document. See x:Bind in ControlTemplate.
But as {x:Bind} markup extension said,
The {x:Bind} markup extension—new for Windows 10—is an alternative to {Binding}. {x:Bind} runs in less time and less memory than {Binding} and supports better debugging.
Finally, I found that the exception is raised because private class Generic_obj2_Bindings.localResources
is null
. no like the generated code for Pages which also uses x:Bind
.
Not sure if It‘s a bug in the generated code. My solution is to modify the file Generic.g.cs.