routed-commands

RoutedUICommand PreviewExecuted Bug?

南楼画角 提交于 2019-11-30 15:18:17
I'm building an application using the MVVM design pattern and I want to make use of the RoutedUICommands defined in the ApplicationCommands class. Since the CommandBindings property of a View (read UserControl) isn't a DependencyProperty we can't bind CommandBindings defined in a ViewModel to the View directly. I solved this by defining an abstract View class which binds this programmatically, based on a ViewModel interface which ensures every ViewModel has an ObservableCollection of CommandBindings. This all works fine, however, in some scenarios I want to execute logic which is defined in

RoutedUICommand PreviewExecuted Bug?

旧街凉风 提交于 2019-11-29 21:19:35
问题 I'm building an application using the MVVM design pattern and I want to make use of the RoutedUICommands defined in the ApplicationCommands class. Since the CommandBindings property of a View (read UserControl) isn't a DependencyProperty we can't bind CommandBindings defined in a ViewModel to the View directly. I solved this by defining an abstract View class which binds this programmatically, based on a ViewModel interface which ensures every ViewModel has an ObservableCollection of

multi key gesture in wpf

醉酒当歌 提交于 2019-11-29 15:17:28
I have a RoutedUICommand called Comment Selection . I need to add an input gesture for this command as it is in VIsual Studio, ie. ( Ctrl+K , Ctrl+C ). How can I do this? Plz help me. (Keep VS functionality in mind). Regards, Jawahar This code is made for "Ctrl+W, Ctrl+E" and/or "Ctrl+W, E" combinations, however you can parametrize it for any key combinations: XAML: <MenuItem Header="Header" InputGestureText="Ctrl+W, E" Command="ShowCommand"/> C#: public static readonly RoutedUICommand ShowCommand = new RoutedUICommand( "Show command text", "Show command desc", typeof(ThisWindow), new

What use has RoutedCommand' class constructor ownertype argument?

偶尔善良 提交于 2019-11-29 09:57:18
The constructor of the RoutedCommand has "owner type" as a last argument. What is its significance? When it is used? MSDN documentation gives completely no clue about why it's needed and whether I could use one type for all commands Quote from MSDN ownerType Type: System.Type The type which is registering the command. There is one more thing. What type should I use when creating new routed commands dynamically from array of names. It looks like that any type works, so I'm using UIElement, but if there is a more suited type for this I would like to know. The source for RoutedCommand shows that

Do I have to use CommandTarget? I thought any focused element would receive the Command

只谈情不闲聊 提交于 2019-11-29 05:05:40
I'm trying to understand how to use RoutedCommands. I was under the impression that if I don't specify a CommandTarget on the Button, any focused element will receive the command. But for some reason it doesn't work. Here is the xaml that doesn't work: <Window x:Class="WpfTest11_Commands2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <TextBox Height="177" HorizontalAlignment="Left" Margin="12,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="233"

WPF Commands, How to declare Application level commands?

旧巷老猫 提交于 2019-11-28 21:25:34
I'm interested in creating commands that are available from anywhere in my WPF application. I'd like them to work in the same way as Cut , Copy , Paste and the other Application level commands, ie: <Button Command="Paste" /> I assumed I could setup CommandBindings for the Application instance, but that property isn't available. How is this done? The best I have managed so far is to create a suite of commands on the top level window and then access them like this...: <Button Command="{x:Static namespace::MainWindow.CommandName}" /> Which works, but is of course tightly coupled, and so extremely

multi key gesture in wpf

元气小坏坏 提交于 2019-11-28 08:57:18
问题 I have a RoutedUICommand called Comment Selection . I need to add an input gesture for this command as it is in VIsual Studio, ie. ( Ctrl+K , Ctrl+C ). How can I do this? Plz help me. (Keep VS functionality in mind). Regards, Jawahar 回答1: This code is made for "Ctrl+W, Ctrl+E" and/or "Ctrl+W, E" combinations, however you can parametrize it for any key combinations: XAML: <MenuItem Header="Header" InputGestureText="Ctrl+W, E" Command="ShowCommand"/> C#: public static readonly RoutedUICommand

How to bind ApplicationCommands to a ViewModel?

旧时模样 提交于 2019-11-28 07:40:46
I have successfully used a few custom commands using MVVM-Light, but I want my application to respond to the standard ApplicationCommands, not just at a Window level, but at a detailed item level as well. I have a TreeView that I want to be able to copy and paste nodes in. Each TreeViewItem has its own ViewModel, and they are displayed via HierarchicalDataTemplates in XAML as there are several different types. I have implemented methods to copy, paste, as well as CanCopy and CanPaste on my ViewModel classes. If appropriate, I could implement MVVM-Light RelayCommands pointing to these easily

What use has RoutedCommand' class constructor ownertype argument?

时光怂恿深爱的人放手 提交于 2019-11-28 03:19:26
问题 The constructor of the RoutedCommand has "owner type" as a last argument. What is its significance? When it is used? MSDN documentation gives completely no clue about why it's needed and whether I could use one type for all commands Quote from MSDN ownerType Type: System.Type The type which is registering the command. There is one more thing. What type should I use when creating new routed commands dynamically from array of names. It looks like that any type works, so I'm using UIElement, but

Boolean CommandParameter in XAML

强颜欢笑 提交于 2019-11-27 20:21:00
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)? H.B. This might be a bit of a hack but you can derive from the KeyBinding class: public class