1

Here is a simplified example of what i need:
I have class A that have a property Name. the Name property is changed asynchronously and there is no way to know when the modification occurs.
In order to show the updated value of it in the view, I wired a propertychanged event in it and bind it with {Binding A.Name}. In the VM it works fine.
But in my case, there is a lot of custom properties that shouldn't be in the class A. I'm thinking once propertychanged is raised in class A, the Name property in AViewModel should get notified and raise the OnPropertyChanged too

is there any way to do so ?

C# :

public class A : BaseViewModel
{
    string name;
    public string Name
    {
        get { return name; }
        set { Set(()=> Name, ref name, value); }
    }
}

public class AViewModel : BaseViewModel
{
    A a;
    public A A 
    {
        get { return a; }
        set { Set(()=> A, ref a, value); }
    }
    public string Name
    {
        get { return A.Name; }
        set { Set(()=> Name, ref A.Name, value); }
    }
}

XAML :

<TextBox Text="{Binding Name}" />
dvhh
  • 4,724
  • 27
  • 33
ihisham
  • 248
  • 1
  • 10
  • 2
    have you tried "RaisePropertyChanged" in the setter on your Name property, then 'UpdateSourceTrigger=PropertyChanged' after the binding on the textbox? – tCoe Jul 18 '16 at 19:23

2 Answers2

2

try to add the "RaisePropertyChanged" to the Name object:

   string name;
    public string Name
    {
        get { return name; }
        set { Set(()=> Name, ref name, value); RaisePropertyChanged();}
    }

Then include the update trigger on the Xaml:

<TextBox Text="{Binding Name}" UpdateSourceTrigger=PropertyChanged />
tCoe
  • 401
  • 1
  • 5
  • 24
1

The class A must have a classic C# event, for example, so the AViewModel can subscribe it.

Igor Damiani
  • 1,897
  • 9
  • 12