Search code examples
c#xamlwinrt-xamlwindows-10windows-10-mobile

Compiled Binding to IsChecked checkbox


I've got CheckBoxes in my list I'm trying to use compiled binding to bind IsChecked propertie...

So I tried this:

<DataTemplate x:DataType="local:RDO">
     <StackPanel Orientation="Horizontal">
        <CheckBox Content="{x:Bind Content}" IsChecked="{x:Bind Check}"/>
     </StackPanel>
</DataTemplate>

And my model class is like this:

class RDO {
    public string Content { get; set; }
    public Boolean Check { get; set; }
}

But it doesn't work and return an error saying

Severity Code Description Project File Line Error Invalid binding path 'Check' : Cannot bind type 'System.Boolean' to 'System.Nullable(System.Boolean)' without a converter

How could I fix this?

and what's difference between Boolean and Nullable(Boolean)?


Solution

  • Your model must implement its Property Check like

     class RDO {
    public string Content { get; set; }
    public Boolean? Check { get; set; }
    }
    

    See the ? on Boolean? ? Nullable is a wrapper for value types (struct) so these can have a value of null (which value types cannot have by default). This is a requirement in your particular case to use binding functionality.

    For further studies:

    https://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx