@ NawedNabiZada Я ценю ваши предложения, но они не работают. Пожалуйста, предлагайте это, только если вы точно знаете, что они работают.
Не уверен, что вы пытались, но моя точка зрения такова:
<Grid>
<StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Child A :"/>
<Label Content="{Binding Path=ChildA.Check}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Child B :"/>
<Label Content="{Binding Path=ChildB.Check}"/>
</StackPanel>
<Button Content="Check/UnCheck" Command="{Binding Path=RefreshBindingCommand}"/>
</StackPanel>
</Grid>
Родитель:
public class Parent : INotifyPropertyChanged
{
public Child ChildA
{
get; set;
}
public Child ChildB
{
get; set;
}
public ICommand RefreshBindingCommand { get; }
public Parent()
{
ChildA = new Child(true);
ChildB = new Child(false);
RefreshBindingCommand = new RelayCommand(RefreshBindingCommand_Execute);
}
void RefreshBindingCommand_Execute(object obj)
{
RefreshBindings();
}
public void RefreshBindings()
{
ChildA.Notify(nameof(ChildA.Check));
ChildB.Notify(nameof(ChildB.Check));
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Ребенок:
public class Child : INotifyPropertyChanged
{
private bool _check;
public bool Check
{
get
{
_check = !_check;
return _check;
}
}
public Child(bool check)
{
_check = check;
}
public void Notify(string property)
{
OnPropertyChanged(property);
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Доказательство того, что это работает: ![enter image description here](https://i.stack.imgur.com/yu96z.gif)