【问题标题】:Failed to assign to property in Creating Custom Component (Winrt)?在创建自定义组件 (Winrt) 中分配给属性失败?
【发布时间】:2013-07-18 08:37:35
【问题描述】:

我正在尝试制作我的自定义组件,但需要帮助。

    private string _passwordText;
    public string PasswordText
    {
        get
        {
            _passwordText = passwordB.Password;
            return _passwordText;
        }
        set
        {
            SetProperty<string>(ref _passwordText, value, "PasswordText");
            passwordB.Password = _passwordText;
            passwordB_PasswordChanged(passwordB, null);
        }
    }


    public event PropertyChangedEventHandler PropertyChanged;

    private bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String propertyName = null)
    {
        if (Equals(storage, value)) return false;

        storage = value;
        OnPropertyChanged(propertyName);
        return true;
    }

    private void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        var handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

AkbankStoreApp.exe 中出现“Windows.UI.Xaml.Markup.XamlParseException”类型的异常,但未在用户代码中处理

WinRT 信息:未能分配给属性“Windows8.StoreApp.Common.CustomControls.WatermarkPasswordTextBox.PasswordText”。 [行:51 位置:26]

【问题讨论】:

    标签: properties user-controls windows-runtime custom-controls


    【解决方案1】:

    您有 OnApplyTemplate 覆盖吗?那是密码B的来源吗?如果是这样,您可能需要在将值分配给其属性之前检查 passwordB 是否不为空。请查看this 以供参考。

    【讨论】:

    • 嗨菲利普,感谢您的关注。我没有 OnApplyTemplate 但我正在检查 passwordB 是否为空。我正在尝试没有 OnApplyTemplate
    猜你喜欢
    • 2015-03-17
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 2016-03-01
    • 1970-01-01
    相关资源
    最近更新 更多