void RestoreUIState(object uiState) { if (uiState == null) { return; } UIContext.RestoreUIState(uiState); var uiel = UIContext.FocusedElement as UIElement ?? UIContext.UIObject as UIElement; if (uiel == null || uiel.IsVisible) { return; } int uiContextVersionTmp = uiContextVersion; new OnVisibleHelper(uiel, () => { if (uiContextVersionTmp == uiContextVersion) { UIContext.RestoreUIState(uiState); } }); }