I have a main form, it has a model of this form in the DataContext . In this model, there is a property that refers to another model. I want to attach a specific form element to the context of the model itself, which is in the property. I tried to write DataContext={Binding anotherModel} , it does not help. even if you use Mode=TwoWay .
Model:
public static MainWindow instance; // статическая ссылка на объект MainWindow private static MyClass _anotherModel = null; // внутренне хранилище значения public static MyClass anotherModel // обработчик изменения значения { get => _anotherModel; set { if (_anotherModel == value) return; _anotherModel = value; instance.PropertyChanged?.Invoke(instance, new PropertyChangedEventArgs("anotherModel ")); } } Form Item:
<TabControl x:Name="Tabs" DataContext="{Binding anotherModel, Mode=TwoWay}"></TabControl> When I check the DataContext this item through a dynamic visual tree , it says BindingExpression and cannot be viewed.
Interesting fact: If you assign a reference to a model to this property before initializing the components, it will be displayed in the inspector and can be viewed.
Mode=TwoWay- this detective allows not only to read but also to write a variable, it has no direct relation to your problem. - NewViewstatic instancetrying to fasten, which does not work. - Andrey NOPObservableCollection, but the binding to it is successful. - Puroinstance.PropertyChanged?.Invokeyou tell the framework that you have updated the property"anotherModel "in the instanceinstance, but it does not have such a property, it is static and does not belong to any instance. - Andrey NOP