1
votes

I have a custom UserControl with the following property in the codebehind:

private bool? _isChecked = false;
public bool? IsChecked
{
    get { return _isChecked; }
    set
    {
        _isChecked = value;
        OnPropertyChanged();
        DetermineVisualState();
    }
}

But when I do the following in my view's XAML:

<customControls:myControl IsChecked="False" />

I get an exception while compiling:

XamlCompiler error WMC0056: Cannot assign to nullable type on property IsChecked

Any workarounds/fixes?

What's funny is that when I override a ToggleButton control, and override the IsChecked property (with the new keyword), this exception also happens... How did Microsoft ever manage to compile the ToggleButton then?

Also it seems to be related to this: https://connect.microsoft.com/VisualStudio/feedback/details/771633/xaml-window-store-apps-cannot-set-nullable-properties-in-xaml

1

1 Answers

1
votes

Please check this article: http://blog.jerrynixon.com/2014/07/lets-code-in-winrt-xaml-you-cannot.html

You must use ThreeState to assign null value.