public async Task SetElement()

in src/AccessibilityInsights/Modes/LiveModeControl.xaml.cs [164:234]


        public async Task SetElement(Guid ecId)
        {
            this.ElementContext = null;
            this.SelectedInHierarchyElement = null;
            EnableSelectorWhenPOISelectedInHierarchy = false;

            var ec = GetDataAction.GetElementContext(ecId);

            if (ec != null)
            {
                var prevFocus = Keyboard.FocusedElement;

                try
                {

                    this.ctrlProgressRing.Activate();

                    this.ctrlHierarchy.IsEnabled = false;
                    ctrlHierarchy.Visibility = Visibility.Visible;
                    svInstructions.Visibility = Visibility.Collapsed;
                    await Task.Run(() =>
                    {
                        CaptureAction.SetLiveModeDataContext(ecId, Configuration.TreeViewMode);
                    }).ConfigureAwait(false);
                    Application.Current.Dispatcher.Invoke(() => {
                        this.ctrlHierarchy.DataContext = ec.DataContext;
                        this.ElementContext = ec;

                        // make sure that  when selected node is changed in hiearchy tree, enable selector.
                        EnableSelectorWhenPOISelectedInHierarchy = true;

                        this.ctrlHierarchy.SetElement(ec);

                        AutomationProperties.SetName(this, string.Format(CultureInfo.InvariantCulture, Properties.Resources.LiveModeControl_LiveInspectWithFormat, ec.Element.Glimpse));
                    });
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception e)
                {
                    e.ReportException();
                    // if there was any exception, make sure that we enable selector later.
                    EnableSelectorWhenPOISelectedInHierarchy = false;
                }
#pragma warning restore CA1031 // Do not catch general exception types
                finally
                {
                    this.ctrlProgressRing.Deactivate();
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        this.ctrlHierarchy.IsEnabled = true;

                        // if the previously focused element is no longer visible and focus has gone to the window,
                        // we will set focus back to the hierarchy control. We do this because disabling the hierarchy control
                        // will throw keyboard focus to mainwindow, where it is not very useful.
                        if (prevFocus is FrameworkElement fe && !fe.IsVisible && Keyboard.FocusedElement is Window)
                        {
                            this.ctrlHierarchy.Focus();
                        }
                    });
                }
            }
            else
            {
                Clear();
            }

            if (EnableSelectorWhenPOISelectedInHierarchy == false)
            {
                Application.Current.Dispatcher.Invoke(() => UpdateStateMachineForLiveMode() );
            }
        }