{x:Bind} function to bool? property doesn't update on null

Author: Sergio0694Created Jan 28, 2020Updated Oct 1, 2026
Labelsbugworking on itarea-Bindingteam-Markupteam-Core

Describe the bug

Having an {x:Bind} to a function targeting a bool? property causes the framework not to refresh the binding (ie. to evaluate the function again) when that target property is set to null. Switching back to a converter works as expected instead, but has another whole series of drawbacks, so it's not really a viable solution for this (higher overhead, verbosity, etc.).

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Declare a bool? property with notification support
  2. Write a static converter that takes a bool? property and returns some value. For instance, just a string with the representation of that input bool? value
  3. Bind that function to some property.
Code example (click to expand)

Model (using MVVMLight):

csharp
public class MyModel : ViewModelBase
{
    private bool? _Property;

    public bool? Property
    {
        get => _Property;
        set => Set(ref _Property, value);
    }
}

Converter:

csharp
public static class MyConverter
{
    public static string Convert(bool? value) => value.ToString();
}

XAML:

xml
<DataTemplate x:DataType="MyModel">
    <TextBlock Text="{x:Bind converters:MyConverter.Convert(Property), Mode=OneWay}"/>
</DataTemplate>

Expected behavior

When setting that property to a value, and then back to null, the binding should evaluate the function again, just like when using a converter instead of a function. Instead, when the property is set to null the binding is not refreshed at all, so the displayed value remains the previous one, which at that point no longer reflects the current value of the target property.

Version Info

  • Windows 10 18362.592
  • SDK 17763
Windows 10 version Saw the problem?
Insider Build (xxxxx)
November 2019 Update (18363)
May 2019 Update (18362) Yes
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Mobile
Xbox
Surface Hub
IoT

Additional context: For whatever reason, using TargetNullValue doesn't work at all either. Not that it should be necessary in the first place, since the converter works fine without it. Also, I tried using FallbackValue and that surprisingly works in this case, but only after the second time the property is set. By that I mean:

  • If the property is initially null, the function is invoked correctly
  • The property is then set to eg. true, the function is invoked correctly
  • The property is set back to null, the function is skipped but FallbackValue works ‍♂

The behavior seems rather inconsistent. Also, using FallbackValue is not really a viable workaround anyway, since FallbackValue only supports strings or x:Null and not eg. a {ThemeResource}, so it's not really that much usable either.

Source: microsoft/microsoft-ui-xaml