public void ActivateControl() { var controlToFocus = this.ViewModel.ParametersPage.IdocItemsView.CurrentItem == null ? (Control)this.IdocItemsComboBox : this.ParameterTreeView; if (controlToFocus == null) { return; } var isVisibleChanged = new ValueHolder <DependencyPropertyChangedEventHandler>(); isVisibleChanged.Value = (sender, e) => { if (!controlToFocus.IsVisible) { return; } var f = controlToFocus.Focus(); Trace.WriteLine(f); controlToFocus.IsVisibleChanged -= isVisibleChanged.Value.EnsureNotNull(); }; if (controlToFocus.IsVisible) { isVisibleChanged.Value(controlToFocus, new DependencyPropertyChangedEventArgs()); } else { controlToFocus.IsVisibleChanged += isVisibleChanged.Value.EnsureNotNull(); } }