How to set a dependency property in the TabControl + WPF UserControl?

Structure such: there is a TabControl, with the same ContentTemplate
 <grid horizontalalignment="Stretch" verticalalignment="Stretch" datacontext="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType={x:Type Window}}}">
 <uc:formulaeditor formulabinding="{Binding CurrentFormula,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" horizontalalignment="Stretch" verticalalignment="Stretch" standardparameters="False">

In the DataContext of the window where the TabControl, served ViewModel where is the property, changing depending on the selected tab
public Formula CurrentFormula
 get => _currentFormula;
 _currentFormula = value;

In UserControl
public static readonly DependencyProperty FormulaBindingProperty =
 DependencyProperty.Register(nameof(FormulaBinding), typeof(Formula), typeof(FormulaEditor),
 new PropertyMetadata(OnFormulaChanged));
public Formula FormulaBinding
 get => GetValue(FormulaBindingProperty) as Formula;
 set => SetValue(FormulaBindingProperty, value);
public FormulaViewModel ViewModel => DataContext as FormulaViewModel;
private static void OnStandardParametersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 var w = d as FormulaEditor;
 if (w.ViewModel != null)
 w.ViewModel.ShowStandardParameters = (bool)e.NewValue;

The problem is this: all this only works when the window is initialized, with the first tab, and when you change CurrentFormula the binding is not updated, and all tabs change CurrentFormula first tab
June 7th 19 at 14:39
1 answer
June 7th 19 at 14:41
The solution is: not to change the DataContext at Control'and. Any change within leads to breakage of the binding.

Find more questions by tags C#WPF