Updating a wpf database after updating an object

I have an object in a presenter connected to a view. Inside my XAMTL, I have the following:

<Label Content="{Binding ElementName=PSV, Path=Presenter.Portfolio.Name}"/>

Now that the control is created, Portfolio is null, then I run another method that sets Portfolio. I implemented INotifyPropertyChanged, but so far I have not been able to call the binding to the binding.

Can someone tell me? Is it possible to bind a property of a property?

+3
source share
4 answers

Binding always works with a DataContext, you will need to set the Presenter to the local DataContext. For example, you can do this in the constructor of your Window or UserControl:

this.DataContext = new Presenter();

:

<Label Content="{Binding ElementName=PSV, Path=Portfolio.Name}"/>

Presenter DataContext.

, DataContext NotifyChanged , Portfolio .

, .

+2

INotifyPropertyChanged, . , :

  • , , .
  • - # 1, - .
  • If this works after No. 1, make sure that the portfolio you are installing has a name at the time of its creation. If not, your portfolio class will also need to implement INotifyPropertyChangedand raise an event when set Name.

Otherwise, send your code.

0
source

Since you have implemented INotifyPropertyChanged, have you not triggered the PropertyChanged event on your Portfolio.Name network device?

string _name;
public string Name
{
get 
{
   return _name;
}
set
{
   _name = value;
   // Alert the databinding engine about changes to the source value
   OnPropertyChanged("Name");
}

void OnPropertyChanged(string propertyName)
{
   if (PropertyChanged != null)
      PropertyChanged(propertyName);
}

#region INotifyPropertyChanged members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
0
source

All Articles