0

This is bindable property in viewmodel

    private string _tooltip;
    public string Tooltip
    {
        get { return _tooltip; }
        set
        {
            _tooltip = value;
            SetProperty(ref _tooltip, value);
        }
    }

xaml

<TextBox HorizontalAlignment="Stretch"
                             Margin="2"
                             Text="{Binding  Path=Tooltip, Mode=TwoWay}"
                             MinWidth="40"
                             Height="24" />

When this tooltip is changed in the viewmodel, view is not updated. How to update the view from source to target?

PRK
  • 177
  • 1
  • 4
  • 15

1 Answers1

1

From the online documentation of BindableBase.SetProperty:

Checks if a property already matches a desired value. Sets the property and notifies listeners only when necessary.

So you must not call _tooltip = value before SetProperty, because if you do, SetProperty will not fire the PropertyChanged event:

private string _tooltip;
public string Tooltip
{
    get { return _tooltip; }
    set { SetProperty(ref _tooltip, value); }
}
Clemens
  • 123,504
  • 12
  • 155
  • 268
  • For the first time, when the VM is initialized it works fine, the tooltip values changes due to some other actions on the page, this change is not reflecting in the view. – PRK Jul 03 '17 at 17:02
  • Did you remove `_tooltip = value` from the property setter? – Clemens Jul 03 '17 at 17:24
  • no, I didn't removed that. if I call RaisePropertyChanges("Tooltip") after setProperty its updating the view. – PRK Jul 03 '17 at 17:31
  • I dont want to pass string to RaisePropertyChanges(), how to achieve the same with SetProperty() – PRK Jul 03 '17 at 17:32