Tugrul Emre Atalay
Tugrul Emre Atalay

Reputation: 938

Failed to assign to property in Creating Custom Component (Winrt)?

I am trying to make my custom component but need help.

    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));
        }
    }

An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in AkbankStoreApp.exe but was not handled in user code

WinRT information: Failed to assign to property 'Windows8.StoreApp.Common.CustomControls.WatermarkPasswordTextBox.PasswordText'. [Line: 51 Position: 26]

Upvotes: 0

Views: 359

Answers (1)

Filip Skakun
Filip Skakun

Reputation: 31724

Do you have an OnApplyTemplate override? Is that where passwordB comes from? If so you might need to check if passwordB is not null before you assign a value to its property. Check this for reference.

Upvotes: 1

Related Questions