1
votes

I have a string property that performs some formatting on a decimal value and I'm binding my textbox to it, on TwoWay mode. When the TextBox loses focus, the setter method of the property is called and i would like to have my getter property to get called again. Is that possible? I've tried the UpdateSource on the binding on the LostFocus event and calling OnPropertyChanged, but both didn't work.

Here's some code:

    public decimal Value { get; set; }

    public string ValueParsed
    {
        get
        {
            return SomeParse(Value);
        }
        set
        {
            Value = SomeParse(value);
        }
    }

and my xaml:

<TextBox Text="{Binding Path=ValueParsed, Mode=TwoWay}"/>

Thanks in advance

1

1 Answers

0
votes

Just add OnPropertyChanged(<property name>) in property setter which will notify UI:

public string ValueParsed
{
    get
    {
        return SomeParse(Value);
    }
    set
    {
        this.Value = SomeParse(value);
        this.OnPropertyChanged("ValueParsed");
    }
}