I have created and used bool to visibility converters before and the other day, I forgot to use a converter on the binding (I am using traditional binding). I bound the visibility property of the control in my view to a bool property in my view model and surprisingly it works. So my question is if it works with traditional binding, why do we need to use converters? Because it seems the compiler is doing the conversion for me.
I tested it on a UWP app in Visual studio Update 3. The minimum app target is 10.0.10586 The target version is 10.0.14393
Interesting. This has always been a pain and it seems to have been fixed without much publicity, I didn't know this.
In WPF you always had to use a ValueConverter, because Visibility isn't a bool.
I just removed a BooleanToVisibility conversion from a {x:Bind ...}
in my project and indeed it still works. I dug this up from the generated code:
private void Update_ViewModel_ShowMessage(global::System.Boolean obj, int phase)
{
...
this.Update_ViewModel_ShowMessage_Cast_ShowMessage_To_Visibility(
obj ? global::Windows.UI.Xaml.Visibility.Visible
: global::Windows.UI.Xaml.Visibility.Collapsed
, phase);
...
}
So apparently it is now built in.
Update:
For {x:Bind }
it was announced here, as part of the anniversary update. And you do need to target 14393 or later. For older builds it only works in {Binding ...}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With