public void Stop() { //Cancel the tutorial InTutorial = false; layer.Remove(managedAdorner); Window parent = UiHelper.FindVisualParent <Window>(managedElement, null); managedAdorner = null; managedElement = null; //Update adorner layer.Update(); //Remove the event parent.KeyDown -= TutorialKeyDown; }
public void Start(FrameworkElement element) { if (InTutorial) { Stop(); return; } //Check if we have a tutorial for this element if (!AllControls.ContainsKey(element.Name)) { return; } //If yes, continue Steps = AllControls[element.Name]; //Make sure we have any steps if (!Steps.Any()) { return; } //If all passed, start the tutorial InTutorial = true; currentStep = 0; //Get element's windows parent managedElement = element; Window parent = UiHelper.FindVisualParent <Window>(managedElement, null); parent.KeyDown += TutorialKeyDown; //Get the second grid, available just after the base adorner decorator. Grid secondGrid = UiHelper.FindVisualChildren <Grid> (UiHelper.FindVisualChildren <AdornerDecorator>(parent).First()).First(); layer = AdornerLayer.GetAdornerLayer(secondGrid); //Create a new Adorner managedAdorner = new TutorialAdorner(managedElement, secondGrid); layer.Add(managedAdorner); //We must dispatch the first update to make sure the arrange is ran Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { //Update adorner layer.Update(); })); }