I have the following in my Entity Framework class:
public int NumberOfIndividualEngagements { get; set; }
public int NumberOfGroupEngagements { get; set; }
[NotMapped]
public int TotalAudienceReached => NumberOfIndividualEngagements + NumberOfGroupEngagements != 0 ? NumberOfIndividualEngagements + NumberOfGroupEngagements : 0;
In the View I have a TextBlock referencing TotalAudienceReached as the text. I also have TextBoxes for the two items in the equation. It seems that when I update the either of the two variables (NumberOfIndividualEngagements, NumberOfGroupEngagements), the TotalAudienceReached does not update and the View is not updated.
Question, is this even possible to accomplish in this manner or do I need to setup some stand alone properties in my ViewModel that references these changes?
EDIT
My VM is as such:
namespace Core
{
public class MyViewModel : BaseViewModel
{
#region Public Properties
/// <summary>
/// The Parent object
/// </summary>
public Parent Parent
{
get => _Parent;
set
{
Parent = _Parent;
OnPropertyChanged(nameof(Parent));
}
}
private Parent _Parent;
// Other properties...
public MyViewModel()
{
// Load it...
}
}
}
Here is my EF dataset
namespace Data
{
[Table("Parent")]
public class Parent : BaseData
{
public int ParentId { get; set; }
public int NumberOfIndividualEngagements { get; set; }
public int NumberOfGroupEngagements { get; set; }
// Other various properties (int, string, bool, etc.)
[NotMapped]
public int TotalAudienceReached => NumberOfIndividualEngagements + NumberOfGroupEngagements != 0 ? NumberOfIndividualEngagements + NumberOfGroupEngagements : 0;
}
}
The DataContext of the View is set to the MyViewModel.
The DataContext of the Container (i.e. Grid, Stackpanel) is set to the Parent property in MyViewModel.
The Controls in the container are bound to the property of the Parent class.
INotifyPropertyChangedin your ViewModel, do some research on this, there is a lot in the SO - Celso Lívero