Created
September 30, 2018 17:07
-
-
Save abfo/67602a2f8b40dbb927a0fd290c9e200f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public partial class MainWindow : Window | |
| { | |
| private DependencyObject _menuFocusScope; | |
| private DependencyObject _toolbarFocusScope; | |
| public MainWindow() | |
| { | |
| InitializeComponent(); | |
| } | |
| private void Window_Loaded(object sender, RoutedEventArgs e) | |
| { | |
| _menuFocusScope = FocusManager.GetFocusScope(menuItemPaste); | |
| _toolbarFocusScope = FocusManager.GetFocusScope(buttonPaste); | |
| } | |
| private void bindingPaste_PreviewCanExecute(object sender, CanExecuteRoutedEventArgs e) | |
| { | |
| IInputElement keyboardFocus = Keyboard.FocusedElement; | |
| if ((keyboardFocus != null) && (keyboardFocus != this)) | |
| { | |
| DependencyObject pasteTargetAsDependencyObjeect = | |
| keyboardFocus as DependencyObject; | |
| if (pasteTargetAsDependencyObjeect != null) | |
| { | |
| DependencyObject targetFocusScope = | |
| FocusManager.GetFocusScope(pasteTargetAsDependencyObjeect); | |
| if ((targetFocusScope != _menuFocusScope) && | |
| (targetFocusScope != _toolbarFocusScope) ) | |
| { | |
| menuItemPaste.CommandTarget = keyboardFocus; | |
| buttonPaste.CommandTarget = keyboardFocus; | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment