T. Israel
T. Israel

Reputation: 229

Remove White spaces from end of string in windows phone 8 XAML and C#

I have a property in a ViewModel called Message, a textbox is bound to it in TwoWay. How can I remove white spaces from the end of whatever string of text is bound to it.

private string message;
    public string Message
    {
        get
        {
            return message;
        }
        set
        {
            SetProperty(ref message, value);
        }
    }

My set Property is defined like this

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

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

Upvotes: 0

Views: 103

Answers (3)

Brakyo
Brakyo

Reputation: 128

in the get method put

get
    {
        return message.TrimEnd();
    }

Upvotes: 0

StillLearnin
StillLearnin

Reputation: 1499

You want the TrimEnd method.

private string message;
public string Message
{
    get
    {
        return message;
    }
    set
    {
        SetProperty(ref message, value.TrimEnd());
    }

https://msdn.microsoft.com/en-us/library/system.string.trimend(v=vs.110).aspx

Upvotes: 2

Mohit S
Mohit S

Reputation: 14064

you may try

this.OnPropertyChanged(propertyName.Trim());

Upvotes: 0

Related Questions