I have Page that contains a button, whose Datacontext is taken from a static resource in this code:
<ObjectDataProvider x:Key="DataContext" ObjectType="{x:Type modelview:ProductionPageModelView}"/>
<Button Content="Save" DataContext="{StaticResource DataContext}" IsEnabled="{Binding HasPandingChanges,UpdateSourceTrigger=PropertyChanged,Mode=OneWay,NotifyOnSourceUpdated=True}"
Command="{Binding ModifyProduction}" Margin="4" HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center"/>
This resource linked to ModelView
and the IsPandingChanges
property is in the base class of ProductionPageModelView
, (you can say the BaseModelView
class).
And I have in the view model class:
public static Dictionary<object, OpertationType> ChangeTracker { get; } = new Dictionary<object, OpertationType>();
public bool HasPandingChanges => ChangeTracker.Count > 0;
when I add an item to ChangeTracker Dictionary, nothing changes and in debug, it shows that it returns true.
I tried to put OnPropertyChanged
in every ChangeTracker.Add
method implementation
public virtual object AddData()
{
DataTransactionType = OpertationType.Insert;
if (ChangeTracker.ContainsKey(this))
{
ChangeTracker[this] = DataTransactionType;
}
else
ChangeTracker.Add(this, DataTransactionType);
OnPropertyChange(nameof(HasPandingChanges));
return null;
}
OnProeprtyChanged Method
protected virtual void OnPropertyChange([CallerMemberName] string Propertyname = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(Propertyname));
}
When I call AddData
. Nothing changed even HasPandingChanges
returns true.