Are there any workarouds to emulate Binding.FallbackValue
behaviour in WinRT?
1 回答
It can be done with attached properties. I've found that many limitations with WinRT can be fixed with them.
I don't have code, but what about this:
<TextBox local:fallbackProperty="Text" local:fallbackPropertyValue="<NO BINDING SET"
Text="{Binding random}" />
now in your attached property handler, you check out fallbackProperty through reflection and subscribe to property changes:
listener = DependencyPropertyChangedListener.Create(this.myTextBox, "Text"); listener.ValueChanged += listener_ValueChanged;
If you receive 0/null then you can swap BINDING out from Text property. And replace it with fallbackPropertyValue. You still need to keep track of real binding and make sure that it gets swaped back in when it's time.
Limitations of this solution is that you can only use one fallbackValue per UI element. But that can easily be extended to "LIST of fallbackValues". Just the syntax wont be as handy anymore.
It's shame though that developers need to reinvent the wheel, while WPF had almost everything in place, and minimum hacks were needed.