2

Since the Anniversary Update (Build 14383 / 14393) you should be able to toggle the visibility of XAML elements without using a converter, like this:

<TextBlock Text="I'm not visible!" Visibility="{x:Bind IsVisibleFalse}" />
<TextBlock Text="I'm visible!" Visibility="{x:Bind IsVisibleTrue}" />

I was trying this in my project, minimum target version set to Windows 10 Anniversary Edition. Unfortunately I did not get it to work.

This code works just fine:

<StackPanel Visibility="{x:Bind ViewModel.IsUnlocked, 
    Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}">

This one doesn't (no error on compile, just does not show up when the bool value changes):

<StackPanel Visibility="{x:Bind ViewModel.IsUnlocked}>

I suspect the Mode="TwoWay" to be the issue, as you can't set it "when the binding expression ends with a cast". This code does not work as well:

<StackPanel Visibility="{x:Bind ViewModel.IsUnlocked,
   Converter={StaticResource BoolToVisibilityConverter}>

So my question is: Am I misssing something or is this not working yet in a MVVM-Scenario and only with code-behind?

Thomas
  • 4,030
  • 4
  • 40
  • 79

2 Answers2

6

The default Mode is OneTime, which renders your code not working. I suggest you use OneWay, which should be usable upon casting.

Dante May Code
  • 11,177
  • 9
  • 49
  • 81
0

Turns out x:Bind defaults to Mode=OneTime - I mistakenly thought it's Mode=OneWay. So this does actually work:

<StackPanel Visibility="{x:Bind ViewModel.IsUnlocked, Mode=OneWay}>
Thomas
  • 4,030
  • 4
  • 40
  • 79