Exemple #1
0
 private void AddCommand(object sender, RoutedEventArgs e)
 {
     // <SnippetCommandingOverviewCmdManagerAddHandlers>
     CommandManager.AddExecutedHandler(helpButton, HelpCmdExecuted);
     CommandManager.AddCanExecuteHandler(helpButton, HelpCmdCanExecute);
     // </SnippetCommandingOverviewCmdManagerAddHandlers>
 }
Exemple #2
0
        public NativeHandleAddInAdapter(FrameworkElement root, ContractHandle adapter, string name = null)
        {
            Debug.Assert(null != root);
            Debug.Assert(null != adapter);
            Debug.Assert(adapter.Contract is IObserverContract);
            root.VerifyAccess();

            observer = adapter;

            var parameters = new HwndSourceParameters(name ?? "AddInWindow")
            {
                ParentWindow = new IntPtr(-3),
                WindowStyle  = 0x40000000
            };

            hwndSource = new HwndSource(parameters)
            {
                RootVisual    = root,
                SizeToContent = SizeToContent.Manual
            };

            if (hwndSource.CompositionTarget != null)
            {
                hwndSource.CompositionTarget.BackgroundColor = Colors.White;
            }

            hwndSource.AddHook(HwndSourceHook);

            CommandManager.AddCanExecuteHandler(root, CanExecuteRoutedEventHandler);
            CommandManager.AddExecutedHandler(root, ExecuteRoutedEventHandler);

            // TODO: Refactoring
            Debug.WriteLine("--\t\t\t\t\t\t\t Handle: {0}\t--\tWindow: {1}", hwndSource.Handle.ToString("x8"), parameters.WindowName);
        }
Exemple #3
0
        public CommandsControl()
        {
            Commands          = new CommandsCollection();
            Commands.Changed += FreezableCollectionChanged;
            _dict             = new Dictionary <ICommand, CommandBinding>();

            CommandManager.AddCanExecuteHandler(this, CanExecute);
            CommandManager.AddExecutedHandler(this, OnExecute);
        }
Exemple #4
0
        private static void PropertyChangedCallback(
            DependencyObject dependencyObject,
            DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            var ui = dependencyObject as UIElement;

            CommandManager.AddCanExecuteHandler(ui, CanExecuteHandler);
            CommandManager.AddExecutedHandler(ui, ExecutedHandler);
        }
Exemple #5
0
        }         // ctor

        /// <summary></summary>
        /// <param name="e"></param>
        protected override void OnInitialized(EventArgs e)
        {
            var env = PpsShellWpf.GetShell(this);

            CommandManager.AddExecutedHandler(this, env.DefaultExecutedHandler);
            CommandManager.AddCanExecuteHandler(this, env.DefaultCanExecuteHandler);

            base.OnInitialized(e);
        }         // proc OnInitialized
        public MenuItem AddFileNewMenuItem(string header, string icon, ICommand click, CanExecuteRoutedEventHandler canExecute, ExecutedRoutedEventHandler execute)
        {
            MenuItem newMenuItem = new MenuItem();

            newMenuItem.Header  = header;
            newMenuItem.Icon    = LoadIcon(icon);
            newMenuItem.Command = click;
            CommandManager.AddCanExecuteHandler(newMenuItem, canExecute);
            CommandManager.AddExecutedHandler(newMenuItem, execute);
            FileNewMI.Items.Add(newMenuItem);
            return(newMenuItem);
        }
Exemple #7
0
        public NativeHandleAddInAdapter(FrameworkElement root, string name = null)
        {
            Debug.Assert(null != root);
            root.VerifyAccess();

            hwndSource = new HwndAsyncSource(root, name);

            hwndSource.AddHook(HwndSourceHook);

            CommandManager.AddCanExecuteHandler(root, CanExecuteRoutedEventHandler);
            CommandManager.AddExecutedHandler(root, ExecuteRoutedEventHandler);

            // TODO: Refactoring
            Debug.WriteLine("--\t\t\t\t\t\t\t Handle: {0}\t--\tWindow: {1}", hwndSource.Handle.ToString("x8"), name);
        }
Exemple #8
0
        /// <summary>Window</summary>
        public PpsWindow()
        {
            InitChrome();

            CommandBindings.AddRange(
                new CommandBinding[]
            {
                new CommandBinding(MinimizeCommand, (sender, e) => WindowState = WindowState.Minimized, (sender, e) => e.CanExecute = true),
                new CommandBinding(MaximizeCommand, (sender, e) => WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized),
                new CommandBinding(CloseCommand, (sender, e) => Close())
            });

            CommandManager.AddExecutedHandler(this, Shell.DefaultExecutedHandler);
            CommandManager.AddCanExecuteHandler(this, Shell.DefaultCanExecuteHandler);
        }         // ctor
Exemple #9
0
 private static void UpdateSourceOnCommandPropertyChangedCallBack(DependencyObject o, DependencyPropertyChangedEventArgs e)
 {
     if (o is ICommandSource)
     {
         var control = o as UIElement;
         if (control != null)
         {
             CommandManager.RemoveExecutedHandler(control, OnCommandExecuted);
             CommandManager.RemoveCanExecuteHandler(control, CanExecuteRoutedEventHandler);
             CommandManager.AddCanExecuteHandler(control, CanExecuteRoutedEventHandler);
             CommandManager.AddExecutedHandler(control, OnCommandExecuted);
             control.PreviewKeyDown               += HandlePreviewKeyDown;
             control.PreviewTextInput             += HandlePreviewTextInput;
             control.IsKeyboardFocusWithinChanged += HandleIsKeyboardFocusWithinChanged;
         }
     }
 }
Exemple #10
0
        private void AddBinding <T>(bool processShortcutsInWPF, ICommand command, Action <T> execute, Predicate <T> canExecute) where T : class
        {
            ExecutedRoutedEventHandler onExecuted = (sender, e) =>
            {
                if (e.Command == command)
                {
                    var cbh = GetInterface <T>();
                    if (cbh != null)
                    {
                        e.Handled = true;
                        if (canExecute(cbh))
                        {
                            execute(cbh);
                        }
                    }
                }
            };
            CanExecuteRoutedEventHandler onCanExecute = (sender, e) =>
            {
                if (e.Command == command)
                {
                    var cbh = GetInterface <T>();
                    if (cbh != null)
                    {
                        e.Handled    = true;
                        e.CanExecute = canExecute(cbh);
                    }
                }
            };

            if (processShortcutsInWPF)
            {
                this.CommandBindings.Add(new CommandBinding(command, onExecuted, onCanExecute));
            }
            else
            {
                // Don't use this.CommandBindings because CommandBindings with built-in shortcuts would handle the key press
                // before WinForms gets to see it. Using the events ensures that the command gets executed only when the user
                // clicks on the menu/toolbar item. (this fixes SD2-1671)
                CommandManager.AddCanExecuteHandler(this, onCanExecute);
                CommandManager.AddExecutedHandler(this, onExecuted);
            }
        }
 public void Attach(IWorkbench workbench)
 {
     if (this.workbench != null)
     {
         throw new InvalidOperationException("Can attach only once!");
     }
     this.workbench = (WpfWorkbench)workbench;
     this.workbench.mainContent.Content = dockingManager;
     CommandManager.AddCanExecuteHandler(this.workbench, OnCanExecuteRoutedCommand);
     CommandManager.AddExecutedHandler(this.workbench, OnExecuteRoutedCommand);
     Busy = true;
     try {
         foreach (PadDescriptor pd in workbench.PadContentCollection)
         {
             ShowPad(pd);
         }
     } finally {
         Busy = false;
     }
     LoadConfiguration();
 }
Exemple #12
0
        }         // ctor

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            charmBarControl  = (PpsWindowPaneCharmBarControl)GetTemplateChild("PART_CharmBar");
            controlPresenter = (ContentPresenter)GetTemplateChild("PART_Control");
            commandBar       = (PpsCommandBar)GetTemplateChild("PART_CommandBar");

            var currentPane = CurrentPane;

            if (currentPane != null)
            {
                charmBarControl.CurrentData = currentPane.CurrentData;
                charmBarControl.HelpKey     = currentPane.HelpKey;
            }

            CommandManager.AddExecutedHandler(this, PaneManager.Shell.DefaultExecutedHandler);
            CommandManager.AddCanExecuteHandler(this, PaneManager.Shell.DefaultCanExecuteHandler);

            UpdateFocus(false);
        }         // proc OnApplyTemplate
        /// <summary>
        /// Invoked when the IsCommandSink attached property is set on an element.
        /// </summary>
        /// <param name="depObj">The element on which the property was set.</param>
        /// <param name="e">Information about the property setting.</param>
        static void OnIsCommandSinkChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e)
        {
            bool isCommandSink = (bool)e.NewValue;

            UIElement sinkElem = depObj as UIElement;

            if (sinkElem == null)
            {
                throw new ArgumentException("Target object must be a UIElement.");
            }

            if (isCommandSink)
            {
                CommandManager.AddCanExecuteHandler(sinkElem, OnCanExecute);
                CommandManager.AddExecutedHandler(sinkElem, OnExecuted);
            }
            else
            {
                CommandManager.RemoveCanExecuteHandler(sinkElem, OnCanExecute);
                CommandManager.RemoveExecutedHandler(sinkElem, OnExecuted);
            }
        }
Exemple #14
0
 public void RegisterCommandHandlers()
 {
     CommandManager.AddExecutedHandler(window, OnCommandExecuted);
     CommandManager.AddCanExecuteHandler(window, OnCommandCanExecute);
 }
 /// <summary>
 /// See <see cref="ICommandManager.AddCanExecuteHandler"/>.
 /// </summary>
 public void AddCanExecuteHandler(UIElement element, CanExecuteRoutedEventHandler handler)
 => CommandManager.AddCanExecuteHandler(element, handler);
 public RibbonButtonsSample()
 {
     InitializeComponent();
     CommandManager.AddExecutedHandler(this, this.OnExecuted);
     CommandManager.AddCanExecuteHandler(this, this.OnCanExecute);
 }
 protected override void OnAttached()
 {
     base.OnAttached();
     CommandManager.AddCanExecuteHandler(AssociatedObject, CanExecute);
 }