System.Windows.UIElement.Focus()

Here are the examples of the csharp api System.Windows.UIElement.Focus() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

549 Examples 7

19 Source : NewRowTemplateBehavior.cs
with MIT License
from Actipro

[SuppressMessage("Microsoft.Portability", "CA1903:UseOnlyApiFromTargetedFramework", MessageId = "System.Windows.Data.CollectionView.#get_NewItemPlaceholder()")]
		private static void OnDataGridRowMouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
			DataGridRow row = sender as DataGridRow;
			if (null == row)
				return;

			DataGridControl datagrid = VisualTreeHelperExtended.GetAncestor(row, typeof(DataGridControl)) as DataGridControl;
			if (null == datagrid)
				return;

			if (CollectionView.NewItemPlaceholder == row.Item) {
				ControlTemplate template = GetTemplate(datagrid);
				if (row.Template == template) {
					row.Template = GetDefaultTemplate(datagrid);
					row.UpdateLayout();

					datagrid.Currenreplacedem = row.Item;

					// 3/23/2010 - Get the first non-read only column (http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=4710)
					DataGridColumn column = datagrid.Columns.FirstOrDefault(col => !col.IsReadOnly);
					if (column != null) {
						DataGridCell cell = VisualTreeHelperExtended.GetAncestor(column.GetCellContent(row), typeof(DataGridCell)) as DataGridCell;

						if (cell != null)
							cell.Focus();
					}

					datagrid.BeginEdit();
				}
			}
		}

19 Source : MainWindow.xaml.cs
with MIT License
from ADeltaX

private void treeView_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            TreeViewItem treeViewItem = (e.OriginalSource as DependencyObject).VisualUpwardSearch<TreeViewItem>();

            if (treeViewItem != null)
            {
                treeViewItem.Focus();
                e.Handled = true;
            }
        }

19 Source : AutoSelectTextBox.cs
with MIT License
from AkiniKites

protected override void OnInitialized(EventArgs e)
        {
            // This will cause the cursor to enter the text box ready to
            // type even when there is no content.
            Focus();
            base.OnInitialized(e);
        }

19 Source : AutoSelectTextBox.cs
with MIT License
from AkiniKites

protected override void OnTextChanged(TextChangedEventArgs e)
        {
            if (_autoSelectAll)
            {
                SelectAll();
                Focus();
                _autoSelectAll = false;
            }
            base.OnTextChanged(e);
        }

19 Source : ContentsBrowser.cs
with MIT License
from alaabenfatma

public void Rename(string fakeName = "", bool forcedToFocus = true)
        {
            try
            {
                if (_tag == null || _renameBox == null)
                    Thread.Sleep(100);
                if (fakeName != "")
                    if (fakeName != null) _renameBox.Text = fakeName;
                    else
                        _renameBox.Text = "";
                _tag.Visibility = Visibility.Collapsed;
                _renameBox.Visibility = Visibility.Visible;
                if (forcedToFocus)
                    _renameBox.Focus();
                _renameBox.CaretIndex = 0;
                _renameBox.SelectAll();
            }
            catch (Exception)
            {
                //Ignored, this kind of errors occurs because of threading mis-behaviours.
            }
        }

19 Source : NodesTree.cs
with MIT License
from alaabenfatma

private void OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.Enter:
                    var hostedNode = ((NodeItem) _tv.SelectedItem)?.HostedNode;
                    if (hostedNode != null)
                    {
                        var node = hostedNode.Clone();
                        var y = ((NodeItem) _tv.SelectedItem).NodeName;
                        InsertNode(node);
                        Remove();
                    }
                    e.Handled = true;
                    break;
                case Key.Left:
                    Collapse();
                    _tb.Focus();

                    e.Handled = true;
                    break;
                case Key.Right:
                    Expand();
                    _tb.Focus();

                    e.Handled = true;
                    break;
                case Key.Up:
                    SelectPrevious();
                    _tb.Focus();
                    e.Handled = true;
                    break;
                case Key.Down:
                    SelectNext();
                    _tb.Focus();
                    e.Handled = true;
                    break;
            }
        }

19 Source : NodesTree.cs
with MIT License
from alaabenfatma

private void Expand()
        {
            _tv.Focus();
            var key = Key.Right;
            var target = Keyboard.FocusedElement;
            var routedEvent = Keyboard.KeyDownEvent;

            if (Keyboard.PrimaryDevice.ActiveSource != null)
                target.RaiseEvent(
                    new KeyEventArgs(
                            Keyboard.PrimaryDevice,
                            Keyboard.PrimaryDevice.ActiveSource,
                            0,
                            key)
                        {RoutedEvent = routedEvent}
                );
        }

19 Source : NodesTree.cs
with MIT License
from alaabenfatma

private void Collapse()
        {
            _tv.Focus();
            var key = Key.Left;
            var target = Keyboard.FocusedElement;
            var routedEvent = Keyboard.KeyDownEvent;

            if (Keyboard.PrimaryDevice.ActiveSource != null)
                target.RaiseEvent(
                    new KeyEventArgs(
                            Keyboard.PrimaryDevice,
                            Keyboard.PrimaryDevice.ActiveSource,
                            0,
                            key)
                        {RoutedEvent = routedEvent}
                );
        }

19 Source : VariablesList.cs
with MIT License
from alaabenfatma

private void _varList_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton != MouseButtonState.Pressed) return;
            if (_varList.SelectedItem == null) return;
            var item = (VariableItem) _varList.SelectedItem;
            var varHoster = new VariableHoster(Host, ref item);
            varHoster.ShowDialog();
            varHoster.Focus();
        }

19 Source : VariablesList.cs
with MIT License
from alaabenfatma

private void VarList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_varList.SelectedItem != null)
            {
                var element = (VariableItem) _varList.SelectedItem;
                _variableName.Text = ((VariableItem) _varList.SelectedItem).Name;
                _variableName.Focus();
                _variableName.CaretIndex = _variableName.Text.Length;
                foreach (var item in Types)
                    if (item.Name.Contains(element.Type))
                        item.Chosen = true;
                foreach (var item in _variables)
                    item.IsSelected = false;
                element.IsSelected = true;
            }
        }

19 Source : NodesTree.cs
with MIT License
from alaabenfatma

private void Filter(string filterstring)
        {
            Task.Factory.StartNew(() =>
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
                {
                    filterstring = filterstring.ToUpper();
                    foreach (var root in _backUpRoots)
                    {
                        if (root.BackUpNodes.Count == 0)
                        {
                            root.BackUpNodes = new List<NodeItem>();
                            foreach (var item in root.Nodes)
                                root.BackUpNodes.Add(item);
                        }
                        if (filterstring != "")
                        {
                            foreach (var item in root.BackUpNodes)
                                if (!item.NodeName.ToUpper().Contains(filterstring))
                                {
                                    root.Nodes.Remove(item);
                                }
                                else
                                {
                                    if (!item.NodeName.ToUpper().Contains(filterstring)) continue;
                                    root.Nodes.Remove(item);
                                    root.Nodes.Add(item);
                                }
                        }
                        else
                        {
                            root.Nodes.Clear();
                            foreach (var item in root.BackUpNodes)
                                root.Nodes.Add(item);
                        }
                    }
                    Roots.Sort();
                    SelectNext();
                    Expand();
                    _tb.Focus();
                }));
            });
        }

19 Source : NodesTree.cs
with MIT License
from alaabenfatma

private void SelectNext()
        {
            _tv.Focus();
            var key = Key.Down;
            var target = Keyboard.FocusedElement;
            var routedEvent = Keyboard.KeyDownEvent;

            if (Keyboard.PrimaryDevice.ActiveSource != null)
                target.RaiseEvent(
                    new KeyEventArgs(
                            Keyboard.PrimaryDevice,
                            Keyboard.PrimaryDevice.ActiveSource,
                            0,
                            key)
                        {RoutedEvent = routedEvent}
                );
        }

19 Source : NodesTree.cs
with MIT License
from alaabenfatma

private void SelectPrevious()
        {
            _tv.Focus();
            var key = Key.Up;
            var target = Keyboard.FocusedElement;
            var routedEvent = Keyboard.KeyDownEvent;

            if (Keyboard.PrimaryDevice.ActiveSource != null)
                target.RaiseEvent(
                    new KeyEventArgs(
                            Keyboard.PrimaryDevice,
                            Keyboard.PrimaryDevice.ActiveSource,
                            0,
                            key)
                        {RoutedEvent = routedEvent}
                );
        }

19 Source : VariablesList.cs
with MIT License
from alaabenfatma

private void VariableName_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (_varList.SelectedItem != null)
            {
                var item = (VariableItem) _varList.SelectedItem;
                item.Name = _variableName.Text;
                var index = _backupVariables.IndexOf(item);
                _backupVariables[index].Name = item.Name;
                RenameNodes(ref item);
            }

            var c = _variables.Count(item => item.Name == _variableName.Text);
            var varListSelectedItem = (VariableItem) _varList.SelectedItem;
            if (varListSelectedItem != null && (c > 1 || varListSelectedItem.Name == ""))
                _variableName.Foreground = Brushes.Red;
            else
                _variableName.Foreground = Brushes.AliceBlue;

            if (Equals(_variableName.Foreground, Brushes.AliceBlue)) return;

            _variableName.Focus();
            _variableName.CaretIndex = _variableName.Text.Length;
            e.Handled = true;
        }

19 Source : Ports.cs
with MIT License
from alaabenfatma

private void OnMouseUp(object o, MouseButtonEventArgs e)
        {
            var sport = Host.TemObjectPort;
            if (Host.WireMode != WireMode.FirstPortSelected) return;
            if (LinkingPossiblity() != 0)
            {
                for (var index = 0; index < ConnectedConnectors.Count; index++)
                {
                    var conn = ConnectedConnectors[index];
                    if (conn.EndPort.ParentNode.Types == NodeTypes.SpaghettiDivider)
                        conn.EndPort.ParentNode.Delete();
                    else if (conn.StartPort.ParentNode.Types == NodeTypes.SpaghettiDivider)
                        conn.StartPort.ParentNode.Delete();
                }
                NodesManager.CreateObjectConnector(Host, sport, this);
                OnLinkChanged();
            }
            else
            {
                Control.Focus();
            }


            Host.Children.Remove(Host.TempConn);
            Host.TemObjectPort = null;
            Host.WireMode = WireMode.Nothing;
            Host.MouseMode = MouseMode.Nothing;
            Host.HideLinkingPossiblity();
            ParentNode.Refresh();
            e.Handled = true;
        }

19 Source : VariablesList.cs
with MIT License
from alaabenfatma

private void Add_Click(object sender, RoutedEventArgs e)
        {
            var item = new VariableItem("");
            _variables.Add(item);
            _backupVariables.Add(item);
            var i = Host.NodesTree.VariablesTreeRootIndex();
            var gereplacedem = new NodeItem("", "Get " + item.Name, new Get(Host, item, false));
            item.Gets--;
            var sereplacedem = new NodeItem("", "Set " + item.Name, new Set(Host, item, false));
            item.Sets--;
            item.NodesTreeItems.Add(gereplacedem);
            item.NodesTreeItems.Add(sereplacedem);
            if (i > -1)
            {
                Host.NodesTree.Roots[i].Nodes.Add(gereplacedem);
                Host.NodesTree.Roots[i].Nodes.Add(sereplacedem);
            }

            _variableName.Focus();
        }

19 Source : EventButtonFocusExtensions.cs
with GNU General Public License v3.0
from alexdillon

private static void ElementToFocusPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            if (sender is ButtonBase button)
            {
                button.Click += (s, args) =>
                {
                    Control control = GetElementToFocus(button);
                    if (control != null)
                    {
                        control.Focus();
                    }
                };
            }
        }

19 Source : SetFocusBehavior.cs
with GNU General Public License v3.0
from alexdillon

protected override void Invoke(object parameter)
        {
            (this.TargetObject as Control)?.Focus();
        }

19 Source : App.cs
with GNU General Public License v3.0
from Amebis

public void SignalExternalCommandLineArgs(IList<string> args)
        {
            // (Re)activate main window.
            if (!MainWindow.IsActive)
                MainWindow.Show();
            MainWindow.Topmost = true;
            try
            {
                MainWindow.Activate();
                MainWindow.Focus();
            }
            finally
            {
                MainWindow.Topmost = false;
            }
        }

19 Source : ConnectWizard.xaml.cs
with GNU General Public License v3.0
from Amebis

private void Open_Click(object sender, RoutedEventArgs e)
        {
            // (Re)activate window.
            if (WindowState == WindowState.Minimized)
                WindowState = WindowState.Normal;
            if (!IsActive)
                Show();
            Topmost = true;
            try
            {
                Activate();
                Focus();
            }
            finally
            {
                Topmost = false;
            }
        }

19 Source : AmRoMessageBox.cs
with MIT License
from AmRo045

private AmRoMessageBoxResult DisplayMessageDialog()
        {
            var messageWindow = new WinMessageBox(ParentWindow)
            {
                WindowBackground = GetSolidBrush(Background),
                TextColor = GetSolidBrush(TextColor),
                IconColor = GetSolidBrush(IconColor),
                RippleEffectColor = GetSolidBrush(RippleEffectColor),
                ClickEffectColor = GetSolidBrush(ClickEffectColor),
                MessageFontSize = MessageFontSize,
                CaptionFontSize = CaptionFontSize,
                FontFamily = FontFamily,
                Message = Message,
                Caption = Caption,
                AmRoMessageBoxButton = MessageBoxButton,
                AmRoMessageBoxIcon = MessageBoxIcon,
                ReverseContentDirection = ReverseContentDirection,
                AmRoMessageBoxDirection = Direction,
                AmRoMessageBoxButtonsText = ButtonsText,
                ParentWindow = ParentWindow,
                ShowMessageWithEffect = ShowMessageWithEffect,
                WindowEffect = new AmRoMessageBoxWindowEffect
                {
                    Color = GetSolidBrush(WindowEffectColor),
                    EffectArea = EffectArea,
                    Opacity = EffectOpacity
                }
            };

            if (ParentWindow != null)
            {
                ParentWindow.Focus();
                ParentWindow.Activate();
            }

            messageWindow.ShowDialog();
            ResetOptions();

            return messageWindow.AmRoMessageBoxResult;
        }

19 Source : TreeViewExtensions.cs
with GNU General Public License v3.0
from AndreiFedarets

private static bool ExpandAndSelecreplacedem(ItemsControl parentContainer, object itemToSelect)
        {
            //check all items at the current level
            foreach (Object item in parentContainer.Items)
            {
                TreeViewItem currentContainer = parentContainer.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;

                //if the data item matches the item we want to select, set the corresponding
                //TreeViewItem IsSelected to true
                if (item == itemToSelect && currentContainer != null)
                {
                    currentContainer.IsSelected = true;
                    currentContainer.BringIntoView();
                    currentContainer.Focus();

                    //the item was found
                    return true;
                }
            }

            //if we get to this point, the selected item was not found at the current level, so we must check the children
            foreach (Object item in parentContainer.Items)
            {
                TreeViewItem currentContainer = parentContainer.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;

                //if children exist
                if (currentContainer != null && currentContainer.Items.Count > 0)
                {
                    //keep track of if the TreeViewItem was expanded or not
                    bool wasExpanded = currentContainer.IsExpanded;

                    //expand the current TreeViewItem so we can check its child TreeViewItems
                    currentContainer.IsExpanded = true;

                    //if the TreeViewItem child containers have not been generated, we must listen to
                    //the StatusChanged event until they are
                    if (currentContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
                    {
                        //store the event handler in a variable so we can remove it (in the handler itself)
                        EventHandler eh = null;
                        eh = delegate
                        {
                            if (currentContainer.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
                            {
                                if (ExpandAndSelecreplacedem(currentContainer, itemToSelect) == false)
                                {
                                    //The replacedumption is that code executing in this EventHandler is the result of the parent not
                                    //being expanded since the containers were not generated.
                                    //since the itemToSelect was not found in the children, collapse the parent since it was previously collapsed
                                    currentContainer.IsExpanded = false;
                                }

                                //remove the StatusChanged event handler since we just handled it (we only needed it once)
                                currentContainer.ItemContainerGenerator.StatusChanged -= eh;
                            }
                        };
                        currentContainer.ItemContainerGenerator.StatusChanged += eh;
                    }
                    else //otherwise the containers have been generated, so look for item to select in the children
                    {
                        if (ExpandAndSelecreplacedem(currentContainer, itemToSelect) == false)
                        {
                            //restore the current TreeViewItem's expanded state
                            currentContainer.IsExpanded = wasExpanded;
                        }
                        else //otherwise the node was found and selected, so return true
                        {
                            return true;
                        }
                    }
                }
            }

            //no item was found
            return false;
        }

19 Source : OpenFileView.xaml.cs
with GNU General Public License v3.0
from AndreiFedarets

private void OnFilesListBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox listBox = (ListBox)sender;
            listBox.Focus();
        }

19 Source : TextAttachedProperties.cs
with MIT License
from angelsix

public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            // If we don't have a control, return
            if (sender is TextBoxBase control)
            {
                if ((bool)e.NewValue)
                {
                    // Focus this control
                    control.Focus();

                    // Select all text
                    control.SelectAll();
                }
            }
            if (sender is PreplacedwordBox preplacedword)
            {
                if ((bool)e.NewValue)
                {
                    // Focus this control
                    preplacedword.Focus();

                    // Select all text
                    preplacedword.SelectAll();
                }
            }
        }

19 Source : TextEditor.cs
with MIT License
from AngryCarrot789

public void HighlightSearchResult(FindResult result, bool focusTextEditor = true)
        {
            if (result.StartIndex >= 0 &&
                result.StartIndex < Text.Length &&
                result.WordLength > 0 &&
                result.StartIndex + result.WordLength <= Text.Length)
            {
                try
                {
                    if (focusTextEditor)
                    {
                        Focus();
                    }

                    Select(result.StartIndex, result.WordLength);
                    ScrollToLine(GetLineIndexFromCharacterIndex(SelectionStart));

                    //int actualLine = GetLineIndexFromCharacterIndex(result.StartIndex);
                    //int finalLine = actualLine + ((int) Math.Round((ActualHeight / FontSize) / 2, 0) ) ;
                    //ScrollToLine(actualLine);
                    //Select(result.StartIndex, result.WordLength);
                }
                catch { }
            }
        }

19 Source : TextAttachedProperties.cs
with MIT License
from angelsix

public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            // If we don't have a control, return
            if (!(sender is Control control))
                return;

            // Focus this control once loaded
            control.Loaded += (s, se) => control.Focus();
        }

19 Source : TextAttachedProperties.cs
with MIT License
from angelsix

public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            // If we don't have a control, return
            if (!(sender is Control control))
                return;

            if ((bool)e.NewValue)
                // Focus this control
                control.Focus();
        }

19 Source : OptionsTTSDictionaryView.xaml.cs
with BSD 3-Clause "New" or "Revised" License
from anoyetta

private void TextBoxSelect(
            object sender,
            MouseButtonEventArgs e)
        {
            if (sender is TextBox textBox)
            {
                if (!textBox.IsKeyboardFocusWithin)
                {
                    textBox.Focus();
                    e.Handled = true;
                }
            }
        }

19 Source : TriggersView.xaml.cs
with BSD 3-Clause "New" or "Revised" License
from anoyetta

private void OnPreviewMouseRightButtonDown(
            object sender,
            MouseButtonEventArgs e)
        {
            var treeViewItem = VisualUpwardSearch(e.OriginalSource as DependencyObject);

            if (treeViewItem != null)
            {
                treeViewItem.Focus();
                e.Handled = true;
            }
        }

19 Source : TriggersView.xaml.cs
with BSD 3-Clause "New" or "Revised" License
from anoyetta

private void RenameTextBoxOnIsVisibleChanged(
            object sender,
            DependencyPropertyChangedEventArgs e)
        {
            if (sender is TextBox t)
            {
                t.SelectAll();
                t.Focus();
            }
        }

19 Source : ColorDialogContent.xaml.cs
with BSD 3-Clause "New" or "Revised" License
from anoyetta

private async void ColorDialogContent_Loaded(object sender, RoutedEventArgs e)
        {
            var item = await Task.Run(() => this.PredefinedColorsListBox.Items.Cast<PredefinedColor>().AsParallel()
                .FirstOrDefault(x => x.Color == this.Color));

            if (item != null)
            {
                this.PredefinedColorsListBox.SelectedItem = item;
                (this.PredefinedColorsListBox.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem)?.Focus();
            }

            if (this.PredefinedColorsListBox.SelectedItem == null &&
                this.Color != null)
            {
                this.RTextBox.Text = this.Color.R.ToString();
                this.GTextBox.Text = this.Color.G.ToString();
                this.BTextBox.Text = this.Color.B.ToString();
                this.ATextBox.Text = !this.IgnoreAlpha ?
                    this.Color.A.ToString() :
                    "255";
            }
        }

19 Source : ColorDialogContent.xaml.cs
with MIT License
from anoyetta

private async void ColorDialogContent_Loaded(object sender, RoutedEventArgs e)
        {
            var item = await Task.Run(() =>
                this.PredefinedColorsListBox.Items.Cast<PredefinedColor>()
                .FirstOrDefault(x => x.Color == this.Color));

            if (item != null)
            {
                this.PredefinedColorsListBox.SelectedItem = item;
                (this.PredefinedColorsListBox.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem)?.Focus();
            }

            if (this.PredefinedColorsListBox.SelectedItem == null &&
                this.Color != null)
            {
                this.RTextBox.Value = this.Color.R;
                this.GTextBox.Value = this.Color.G;
                this.BTextBox.Value = this.Color.B;
                this.ATextBox.Value = !this.IgnoreAlpha ? this.Color.A : 255;
            }
        }

19 Source : WebDisplayManager.cs
with MIT License
from AntonyCorbett

private void HandleBrowserLoadingStateChanged(object? sender, LoadingStateChangedEventArgs e)
        {
            if (e.IsLoading)
            {
                StatusEvent?.Invoke(this, new WebBrowserProgressEventArgs
                {
                    Description = Properties.Resources.WEB_LOADING,
                });
            }
            else
            {
                StatusEvent?.Invoke(this, new WebBrowserProgressEventArgs { Description = string.Empty });
            }

            Application.Current.Dispatcher.Invoke(async () =>
            {
                Log.Debug(e.IsLoading ? $"Loading web page = {_browser.Address}" : "Loaded web page");

                if (!e.IsLoading && !_showing && _currentMediaItemUrl != null)
                {
                    // page is loaded so fade in...
                    _showing = true;
                    await InitBrowserFromDatabase(_currentMediaItemUrl);

                    FadeBrowser(true, () =>
                    {
                        OnMediaChangeEvent(CreateMediaEventArgs(_mediaItemId, MediaChange.Started));
                        _browserGrid.Focus();

                        if (_useMirror)
                        {
                            ShowMirror();
                        }
                    });
                }
            });
        }

19 Source : VisibilityFocusBehaviour.cs
with MIT License
from AntonyCorbett

private static void ElementIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (sender is UIElement visibilityElement && visibilityElement.IsVisible)
            {
                visibilityElement.Focus();
            }
        }

19 Source : PreviewViewModel.cs
with MIT License
from AntonyCorbett

private void ToggleDisplayImage()
        {
            _displayWindowService.ToggleWindow();

            if (IsDisplayWindowVisible)
            {
                _displayWindowService.SetImage(_imagesService.Get(_imageIndex ?? 0));
            }

            RaisePropertyChanged(nameof(IsDisplayWindowVisible));
            RaisePropertyChanged(nameof(DisplayButtonToolTip));

            // retain focus and so allow F5 to work.
            Application.Current?.MainWindow?.Focus();
        }

19 Source : TreeView.cs
with GNU General Public License v3.0
from AnyStatus

private void OnLoaded(object sender, RoutedEventArgs e)
        {
            Unloaded += OnUnloaded;
            MouseDown += OnMouseDown;
            SelectedItemChanged += OnSelectedItemChanged;
            PreviewMouseRightButtonDown += OnPreviewMouseRightButtonDown;
            AddHandler(TreeViewItem.SelectedEvent, (RoutedEventHandler)OnTreeViewItemSelected);
            AddHandler(TreeViewItem.UnselectedEvent, (RoutedEventHandler)OnTreeViewItemUnselected);
            Focus();
        }

19 Source : TreeView.cs
with GNU General Public License v3.0
from AnyStatus

private static void OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (VisualUpwardSearch<TreeViewItem>(e.OriginalSource as DependencyObject) is TreeViewItem treeViewItem)
            {
                treeViewItem.IsSelected = true;

                treeViewItem.Focus();

                e.Handled = true;
            }
        }

19 Source : SelectPathDialog.xaml.cs
with MIT License
from arasplm

private void TreeViewItem_MouseRightButtonDown(object sender, MouseEventArgs e)
		{
			TreeViewItem item = sender as TreeViewItem;
			if (item != null)
			{
				item.Focus();
				e.Handled = true;
			}
		}

19 Source : ExpressionWindow.xaml.cs
with GNU General Public License v3.0
from armandoalonso

private void SelectivelyIgnoreMouseButton(object sender, MouseButtonEventArgs e)
        {
            if (sender is TextBox tb && !tb.IsKeyboardFocusWithin)
            {
                e.Handled = true;
                tb.Focus();
            }
        }

19 Source : WorkspacePageView.xaml.cs
with MIT License
from aschearer

private void OnLoaded(object sender, RoutedEventArgs e)
        {
            this.Focus();
            this.PieChart.Series = new SeriesCollection();
            var viewModel = this.DataContext as WorkspacePageViewModel;
            viewModel.Roots.CollectionChanged += this.OnCollectionChanged;
            bool shouldAddFocus = true;
            foreach (var root in viewModel.Roots)
            {
                this.AddFileToChart(root);
                if (shouldAddFocus)
                {
                    root.IsSelected = true;
                    this.TreeView.Focus();
                    shouldAddFocus = false;
                }
            }
        }

19 Source : StartPageView.xaml.cs
with MIT License
from aschearer

private void OnLoaded(object sender, RoutedEventArgs e)
        {
            this.Focus();
        }

19 Source : MainWindow.xaml.cs
with MIT License
from awaescher

private void txtFilter_Finish(object sender, EventArgs e)
		{
			lstRepositories.Focus();
			if (lstRepositories.Items.Count > 0)
			{
				lstRepositories.SelectedIndex = 0;
				var item = (ListBoxItem)lstRepositories.ItemContainerGenerator.ContainerFromIndex(0);
				item?.Focus();
			}
		}

19 Source : AyTableViewCell.cs
with MIT License
from ay2015

protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseRightButtonDown(e);
            _column.FocusColumn();
            Focus();
        }

19 Source : AyTableViewColumnHeader.cs
with MIT License
from ay2015

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            Focus();
            Column.FocusColumn();
            base.OnMouseLeftButtonDown(e);
        }

19 Source : TreeViewHelper.cs
with MIT License
from ay2015

private static bool ExpandAndSelecreplacedem(ItemsControl parentContainer, object itemToSelect)
        {
            //check all items at the current level
            foreach (Object item in parentContainer.Items)
            {
                TreeViewItem currentContainer = parentContainer.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
                //if the data item matches the item we want to select, set the corresponding
                //TreeViewItem IsSelected to true
                if (item == itemToSelect && currentContainer != null)
                {
                    currentContainer.IsSelected = true;
                    currentContainer.BringIntoView();
                    currentContainer.Focus();
                    //the item was found
                    return true;
                }
            }
            //if we get to this point, the selected item was not found at the current level, so we must check the children
            foreach (Object item in parentContainer.Items)
            {
                TreeViewItem currentContainer = parentContainer.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
                //if children exist
                if (currentContainer != null && currentContainer.Items.Count > 0)
                {
                    //keep track of if the TreeViewItem was expanded or not
                    bool wasExpanded = currentContainer.IsExpanded;
                    //expand the current TreeViewItem so we can check its child TreeViewItems
                    currentContainer.IsExpanded = true;
                    //if the TreeViewItem child containers have not been generated, we must listen to
                    //the StatusChanged event until they are
                    if (currentContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
                    {
                        //store the event handler in a variable so we can remove it (in the handler itself)
                        EventHandler eh = null;
                        eh = new EventHandler(delegate
                        {
                            if (currentContainer.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
                            {
                                if (ExpandAndSelecreplacedem(currentContainer, itemToSelect) == false)
                                {
                                    //The replacedumption is that code executing in this EventHandler is the result of the parent not
                                    //being expanded since the containers were not generated.
                                    //since the itemToSelect was not found in the children, collapse the parent since it was previously collapsed
                                    currentContainer.IsExpanded = false;
                                }
                                //remove the StatusChanged event handler since we just handled it (we only needed it once)
                                currentContainer.ItemContainerGenerator.StatusChanged -= eh;
                            }
                        });
                        currentContainer.ItemContainerGenerator.StatusChanged += eh;
                    }
                    else //otherwise the containers have been generated, so look for item to select in the children
                    {
                        if (ExpandAndSelecreplacedem(currentContainer, itemToSelect) == false)
                        {
                            //restore the current TreeViewItem's expanded state
                            currentContainer.IsExpanded = wasExpanded;
                        }
                        else //otherwise the node was found and selected, so return true
                        {
                            return true;
                        }
                    }
                }
            }
            //no item was found
            return false;
        }

19 Source : AyKeyboardPicker.cs
with MIT License
from ay2015

protected override void Invoke(object parameter)
        {
            if (Target != null)
            {
                Target.Focus();
            }
            SystemHelper.ShowKeyBoard();
        }

19 Source : AyTableViewCell.cs
with MIT License
from ay2015

private void ActionDown()
        {
            _column.FocusColumn();
            if (ParentTableView.RowClickMode == AyTableView.RowClickModes.CellEdit)
            {
                if (ParentTableView.SelectedCell != null)
                {
                    //ParentTableView.SelectedCell.CloseEditCell();
                }
                //OpenEditCell();
            }
            Focus();

        }

19 Source : AyTableViewCell.cs
with MIT License
from ay2015

private void ActionEnter()
        {
            if (ParentTableView.SelectionMode == AyTableViewSelectionMode.RowTenSingle || AyTableViewSelectionMode.RowTenNoSelect == ParentTableView.SelectionMode)
            {
                if (ParentTableView != null)
                    ParentTableView.EnterColumnChanged(_column);
                Focus();
            }
        }

19 Source : AyTextBoxBase.cs
with MIT License
from ay2015

protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);
            if (AutoSelected != 0 && !base.IsKeyboardFocusWithin)
            {
                Focus();
                e.Handled = true;
            }
        }

19 Source : AyTableViewRowsPresenter.cs
with MIT License
from ay2015

private void OnStatusChanged(object sender, EventArgs e)
        {
            if (this.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
            {
                this.ItemContainerGenerator.StatusChanged -= OnStatusChanged;

                var el2 = this.ItemContainerGenerator.ContainerFromIndex(_focusedRowIndex) as FrameworkElement;
                if (el2 != null)
                {
                    el2.Focus();
                    el2.BringIntoView();
                }
            }
        }

See More Examples