简体   繁体   English

已编译的“绑定到IsChecked”复选框

[英]Compiled Binding to IsChecked checkbox

I've got CheckBoxes in my list I'm trying to use compiled binding to bind IsChecked propertie... 我的清单中有CheckBoxes,我想使用已编译的绑定来绑定IsChecked属性...

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 严重性代码说明项目文件行错误绑定路径'Check'无效:如果没有转换器,则无法将类型'System.Boolean'绑定到'System.Nullable(System.Boolean)'

How could I fix this? 我该如何解决?

and what's difference between Boolean and Nullable(Boolean)? 和Boolean和Nullable(Boolean)有什么区别?

Your model must implement its Property Check like 您的模型必须实现其属性Check例如

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

See the ? 看到了? on Boolean? Boolean? ? Nullable is a wrapper for value types ( struct ) so these can have a value of null (which value types cannot have by default). Nullable是值类型( struct )的包装,因此它们可以具有null (默认情况下不能具有值类型)。 This is a requirement in your particular case to use binding functionality. 在特定情况下,这是使用绑定功能的要求。

For further studies: 进一步研究:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM