UWP:自定义 UserControl 布尔? 属性
UWP: Custom UserControl bool? property
我有一个自定义用户控件,其代码隐藏中包含以下 属性:
private bool? _isChecked = false;
public bool? IsChecked
{
get { return _isChecked; }
set
{
_isChecked = value;
OnPropertyChanged();
DetermineVisualState();
}
}
但是当我在我的视图 XAML 中执行以下操作时:
<customControls:myControl IsChecked="False" />
编译时出现异常:
XamlCompiler error WMC0056: Cannot assign to nullable type on property IsChecked
任何workarounds/fixes?
有趣的是,当我重写 ToggleButton 控件并重写 IsChecked 属性(使用 new 关键字)时,也会发生此异常......微软当时是如何设法编译 ToggleButton 的?
请查看这篇文章:http://blog.jerrynixon.com/2014/07/lets-code-in-winrt-xaml-you-cannot.html
您必须使用 ThreeState 来分配空值。
我有一个自定义用户控件,其代码隐藏中包含以下 属性:
private bool? _isChecked = false;
public bool? IsChecked
{
get { return _isChecked; }
set
{
_isChecked = value;
OnPropertyChanged();
DetermineVisualState();
}
}
但是当我在我的视图 XAML 中执行以下操作时:
<customControls:myControl IsChecked="False" />
编译时出现异常:
XamlCompiler error WMC0056: Cannot assign to nullable type on property IsChecked
任何workarounds/fixes?
有趣的是,当我重写 ToggleButton 控件并重写 IsChecked 属性(使用 new 关键字)时,也会发生此异常......微软当时是如何设法编译 ToggleButton 的?
请查看这篇文章:http://blog.jerrynixon.com/2014/07/lets-code-in-winrt-xaml-you-cannot.html
您必须使用 ThreeState 来分配空值。