Why bool works for visibility without a converter when using traditional binding

I created and used bool for the converters of visibility before and after the day, I forgot to use the converter on the binding (I use the traditional binding). I have bound the visibility property of the control, in my opinion, to the bool property in my view model and, surprisingly, this works. So my question is, does it work with traditional binding, why do we use converters? Because it seems that the compiler is doing the conversion for me.

I tested it in a UWP application in Visual Studio Update 3. The minimum goal for the application is 10.0.10586. The target version is 10.0.14393.

+5
source share
1 answer

Interesting. This has always been a pain, and it seems that it was fixed without much advertising, I did not know that.

In WPF, you always had to use ValueConverter because Visibility is not a bool.

I just removed the BooleanToVisibility conversion from {x:Bind ...} to my project and it really still works. I dug this 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); ... } 

Thus, it is obvious that it is now inline.

Update:

For {x:Bind } was announced here as part of the anniversary update. And you need to target 14393 or later. For older collectors, it only works in {Binding ...} .

+7
source

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


All Articles