routed-commands

WPF Two Commands handlers, One Command

假如想象 提交于 2020-01-22 15:21:09
问题 Im deriving from a third party control. It is implementing ApplicationCommands.SelectAll. However the behaviour i want is slightly different. there is no virtual method i can override, and when i register a class handler, like so CommandManager.RegisterClassCommandBinding(typeof(MyDerivedControl), new CommandBinding(ApplicationCommands.SelectAll, new ExecutedRoutedEventHandler(OnExecutedSelectAll), new CanExecuteRoutedEventHandler(OnCanExecuteSelectAll))); My methods do not get called. The

RoutedCommands that use tunneling instead of bubbling

可紊 提交于 2020-01-14 16:34:38
问题 I have a custom control ( MyControl ) that exposes a custom command. I want the parent Window to be able to invoke this command, and all MyControls should react to it. I have added the command to MyControl 's CommandBindings collection, which also provides a CanExecute callback that always returns true. My problem is that a menu item that invokes this command never gets enabled. I'm presuming this is because the menu is above the MyControls in the visual tree, but to be honest I'm a little

WPF - Why do ContextMenu items work for ListBox but not ItemsControl?

不打扰是莪最后的温柔 提交于 2020-01-04 02:57:13
问题 Items in a list have context menus. The context menu items are bound to routed commands. The context menu items work correctly if the list control is a ListBox , but as soon as I downgrade it to an ItemsControl it no longer works. Specifically the menu items are always greyed out. The CanExecute callback in my CommandBinding is not being called either. What is it about ListBox that allows context menu items with commands to bind correctly? Here are some excerpts from a sample app I put

DelegateCommand vs RoutedCommand and gestures - WPF

我们两清 提交于 2020-01-02 09:56:32
问题 is there anyway for DelegateCommand's to support gestures when building a composite WPF app? I'm trying to create a command used by a MenuItem and also a Button, which can be accessed through a keyboard shortcut, but which sits inside a class in a separate assembly. I can use a RoutedCommand, but I want to minimise any code-behind. 回答1: Use InputBindingCollection to map gestures with ICommand. 来源: https://stackoverflow.com/questions/2297321/delegatecommand-vs-routedcommand-and-gestures-wpf

Can I use Caliburn to bind to RoutedCommands?

不想你离开。 提交于 2020-01-02 08:01:50
问题 What's the best way to use WPF's built-in RoutedCommands with Caliburn? For example, in my shell I have an Edit menu with a Copy item in it attached to the standard command found in ApplicationCommands : <Menu> <MenuItem Header="Edit"> <MenuItem Header="Copy" Command="ApplicationCommands.Copy" /> </MenuItem> </Menu> I want this item to be handled by a TextBox when it has the focus and by my own controls when they have the focus. In my controls I can handle Execute and CanExecute in code

Implement custom Copy and Paste in WPF DataGrid which works when there are no rows in it

爱⌒轻易说出口 提交于 2020-01-01 09:38:50
问题 I need to implement a custom copy + cut + paste for data (not text or CSV) to be copied between grids in a WPF application. Using standard ApplicationCommands and defining CommandBinding works really well but only if the DataGrid contains at least 1 row of data and when it's selected. When there are no rows or focus is not on any of them, all commands are disabled. To fix the problem I tried calling CommandManager.InvalidateRequerySuggested() and setting Focusable=true and/or FocusManager

MenuItem in Window, CommandBinding in UserControl

天涯浪子 提交于 2019-12-25 02:51:50
问题 I have a window: <Window x:Class="SomeNamespace.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="350" Width="525"> <Window.CommandBindings> <CommandBinding Command="ApplicationCommands.Copy" CanExecute="CommandCanExecute" Executed="CommandExecuted"/> </Window.CommandBindings> <DockPanel> <Menu DockPanel.Dock="Top"> <MenuItem Header="File"> <MenuItem Command="ApplicationCommands.Copy"/> </MenuItem> <

Execute a method on second control from the first control in WPF

早过忘川 提交于 2019-12-25 01:16:26
问题 My ViewControl has a method called ZoomIn() . How can I execute this method on this ViewControl by clicking Button control without going to code-behind. <controls:ViewControl/> <Button Content="Zoom In"/> ViewControl.xaml.cs: public void ZoomIn() { double actualWidth = m_child.ActualWidth; double actualHeight = m_child.ActualHeight; double x = (0.5 * actualWidth - Dx) / Scale; double y = (0.5 * actualHeight - Dy) / Scale; float startScale = Scale; Scale = Math.Min(Scale * ZoomFactor, ZoomMax)

RoutedCommand in UserControl is not working as expected

耗尽温柔 提交于 2019-12-25 01:13:54
问题 I am trying to use RoutedCommands in my UserControls inspired by this article from Josh Smith. https://joshsmithonwpf.wordpress.com/2008/03/18/understanding-routed-commands/ I did it a bit different from the example in the article and defined the RoutedCommand and CommandBindings in the Usercontrol. Now I am trying to use it my MainWindow. So that by clicking the Button, the Command in UserControl is executed. Unfortunately what I get is a disabled button. The Foo_CanExecute() method is never

Passing ListView Items to Commands using Prism Library

ぃ、小莉子 提交于 2019-12-24 15:24:12
问题 I'm trying to execute methods based on listview items data. In addition to that, the button, which triggers the command, should only be enabled, if "CanExecute" method of the listview item returns true. Both methods, "MyCommand" and "CanExecute", are included in my ViewModel. Unfortunately I'm not sure how to pass the items information correctly to both methods in order to be conform with the PRISM 6 framework. So my first approach was to do it like the following : Model public class MyModel