UWP:Custom UserControl bool?属性

时间:2016-05-21 23:11:55

标签: c# wpf user-controls uwp

我有一个自定义的UserControl,在codebehind中有以下属性:

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

但是当我在我的视图XAML中执行以下操作时:

extension UIPageViewController: UIScrollViewDelegate {

    public override func viewDidLoad() {
        super.viewDidLoad()

        for subview in view.subviews {
            if let scrollView = subview as? UIScrollView {
                scrollView.delegate = self
            }
        }
    }

    public func scrollViewDidScroll(scrollView: UIScrollView) {
        let point = scrollView.contentOffset
        var percentComplete: CGFloat
        percentComplete = fabs(point.x - view.frame.size.width)/view.frame.size.width
        NSLog("percentComplete: %f", percentComplete)
    }
}

我在编译时遇到异常:

{{1}}

有任何解决方法/修复方法吗?

有趣的是,当我覆盖ToggleButton控件并覆盖IsChecked属性(使用new关键字)时,也会发生此异常...... Microsoft如何设法编译ToggleButton呢?

它似乎与此有关:https://connect.microsoft.com/VisualStudio/feedback/details/771633/xaml-window-store-apps-cannot-set-nullable-properties-in-xaml

1 个答案:

答案 0 :(得分:1)

请查看此文章:http://blog.jerrynixon.com/2014/07/lets-code-in-winrt-xaml-you-cannot.html

您必须使用ThreeState指定空值。