routed-commands

In WPF how do I implement ICommandSource to give my custom control ability to use Command from xaml?

六月ゝ 毕业季﹏ 提交于 2019-12-21 07:38:06
问题 Could you please provide a sample, of how do you implement the ICommandSource interface. As I want my UserControl , which doesn't have the ability to Specify command in xaml, to have this ability. And to be able to handle the command when user clicks on the CustomControl . 回答1: Here's an example : public partial class MyUserControl : UserControl, ICommandSource { public MyUserControl() { InitializeComponent(); } public ICommand Command { get { return (ICommand)GetValue(CommandProperty); } set

RoutedCommands Executed and PreviewExecuted events

旧街凉风 提交于 2019-12-19 06:24:10
问题 My problem is that I would like to handle a commands in multiple places. For instance I have my custom UserControl where a Button is bound to some command. I have a command binding in that control but I also have a command binding in a Window which uses this control. My aim is to perform some action inside the control while not interrupting handling of the command in the Window. I tried experimenting with Executed and PreviewExecuted events but with no luck. Then I simulated the problem in a

Boolean CommandParameter in XAML

て烟熏妆下的殇ゞ 提交于 2019-12-17 15:55:05
问题 I have this code (which works just right): <KeyBinding Key="Enter" Command="{Binding ReturnResultCommand}"> <KeyBinding.CommandParameter> <s:Boolean> True </s:Boolean> </KeyBinding.CommandParameter> </KeyBinding> Where "s" is of course the System namespace. But this command is called quite a few times and it really inflates otherwise rather simple XAML code. Is this really the shortest notation of boolean command parameter in XAML (other than splitting the command into several commands)? 回答1:

How to launch RoutedCommand on application level in multiple windows pattern?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 13:42:54
问题 I have a multiple windows in an application, for instance, window1, window2 and window3. one RoutedCommand (with KeyGesture F11) was binded in window1. How to launch that routed command by pressing F11, while window2 had input focus ? In WinForm application, i use MessageFilter to detect F11, but in WPF, how to do that ? 回答1: You can use CommandManager.RegisterClassCommandBinding to hook up a handler to every Window application wide. This will be continue working for the rest of your

How to bind a RelayCommand(MVVM) to a RoutedCommand? (CommandBinding)

放肆的年华 提交于 2019-12-11 08:15:10
问题 I want to create a custom class of a CommandBinding, where a RelayCommand of my ViewModel is executed when the RoutedCommand is executed. Currently there is only the possibility to create CommandBindings which have Executed methods in the codebehind class. Example: <CommandBinding Command="ApplicationCommands.Close" Executed="CloseCommandHandler" CanExecute="CanExecuteHandler"/> This needs the CloseCommandHandler methode in the code behind. I would want to write the following. <CommandBinding

How to rewrite WPF routed commands dispatching mechanism

跟風遠走 提交于 2019-12-10 19:29:54
问题 Can I extend WPF commands routing in a way so it would first check whether command can be invoked in the focused field and if not in some other (never changing)? Is there any hooks for that? Maybe you don't know whether that would work but saw something similar somewhere on the net and can spare the link? Abstract example For example if I would be writing a text editor with a side panel and panel would have the focus. If I would press Ctrl+G some command will be invoked because panel has

WPF Architecture Confusion RE: Routed Commands, Events, and Gestures

 ̄綄美尐妖づ 提交于 2019-12-07 22:40:17
问题 In learning WPF, I've been reading scads of books and web sites. One thing that seems to keep evading me is how we are supposed to properly wire up RoutedCommands. In one article, the author pointed out that the codebehind for your XAML files is supposed to contain nothing more than the call to InitializeComponent. I can get behind that. It makes the XAML file nothing more than a presentation document, and satisifies my unholy craving for separation of concerns. On the other hand, every

Should I check an ICommand's CanExecute method before calling Execute from procedural code?

ⅰ亾dé卋堺 提交于 2019-12-06 23:04:32
问题 When using ICommand s in XAML, WPF uses the CanExecute method to enable or disable controls associated with the command. But what if I am calling Execute from procedural code? Should I first check CanExecute to make sure that the command can execute, or should Execute take care of this check for me? In other words, should I do this: if (someCommand.CanExecute(parameter, target)) someCommand.Execute(parameter, target); Or just this: someCommand.Execute(parameter, target); 回答1: Good style would

WPF Architecture Confusion RE: Routed Commands, Events, and Gestures

半世苍凉 提交于 2019-12-06 14:32:08
In learning WPF, I've been reading scads of books and web sites. One thing that seems to keep evading me is how we are supposed to properly wire up RoutedCommands. In one article, the author pointed out that the codebehind for your XAML files is supposed to contain nothing more than the call to InitializeComponent. I can get behind that. It makes the XAML file nothing more than a presentation document, and satisifies my unholy craving for separation of concerns. On the other hand, every sample I've seen that addresses double-click events seems to want you to write code. It was my understanding

Can I use Caliburn to bind to RoutedCommands?

試著忘記壹切 提交于 2019-12-05 19:55:29
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 behind by creating a CommandBinding : <UserControl.CommandBindings> <CommandBinding Command=