wpf-commands

WPF, UserControl, and Commands? Oh my!

(This question is related to another one, but different enough that I think it warrants placement here.) Here's a (heavily snipped) Window: <Window x:Class="Gmd.TimeTracker2.TimeTrackerMainForm" xmlns:local="clr-namespace:Gmd.TimeTracker2" xmlns:localcommands="clr-namespace:Gmd.TimeTracker2.Commands" x:Name="This" DataC...

WPF - Get Hyperlink command from data?

In WPF, how can I get a reference to the Command that a Hyperlink should invoke from an object property? I am creating a WPF application, using the MVVM pattern. A list box in the main window dislays hyperlinks. Each hyperlink will invoke one of the view model's ICommand properties when it is clicked. How do I specify which ICommand sho...

Refresh WPF Command

Does anyone know how I can force CanExecute to get called on a custom command (Josh Smith's RelayCommand)? Typically, CanExecute is called whenever interaction occurs on the UI. If I click something, my commands are updated. I have a situation where the condition for CanExecute is getting turned on/off by a timer behind the scenes. Be...

Prevent double-click from double firing a command

Given that you have a control that fires a command: <Button Command="New"/> Is there a way to prevent the command from being fired twice if the user double clicks on the command? EDIT: What is significant in this case is that I am using the Commanding model in WPF. It appears that whenever the button is pressed, the command is execu...

Specify Command for MenuItem in a DataTemplate

I have a context menu. It's bound to some collection and it has a defined ItemTemplate like this: <ContextMenu ItemsSource={Binding ...} ItemTemplate={StaticResource itemTemplate} /> itemTemplate is a simple DataTemplate with a TextBlock: <DataTemplate x:Key="itemTemplate"> <TextBlock Text={Binding ...} /> </DataTempl...

CommandBinding in Window doesn't catch execution of command from ContextMenu

A quite simple and straightforward example. I have a window. It has CommandBindings set to catch a RoutedUICommand execution. <Window ... > <Window.CommandBinding> <CommandBinding Command="{x:Static local:Commands.Command1}" Executed="OnCommand1Executed" CanExecute="OnCanCommand1Exec...

Passing origin of ContextMenu into WPF Command

Interesting problem related to firing commands from context menu items... I want to fire a command to insert a row in my control, InsertRowCmd. This command needs to know where to insert the row. I could use Mouse.GetPosition(), but that would get me the position of the mouse currently, which would be over the menu item. I want to get...

Redirection Between View In MVVM

I am using MVVM patern for developing my WPF application. It working fine for unrelated pages, means how to go in another view from one view. Eg: I have one list page in which some records are coming from one ViewModel and another from another ViewModel, means I have two ViewModel form my single View. And now I want to display another ...

WPF Built-in Commands

I'm looking for a complete list of built-in WPF Commands. The best list I've found so far is here, but it does not list all commands. Some nice-to-have details would be: Controls/components with support to the commands (for example, TextBox supports edit commands such as Paste, Copy, Cut, Redo, and Undo); Default Key Gestures and UI ...

How to bind a ComboBoxItem's IsEnabled property to the result of a Command's CanExecute method.

I've a custom SplitButton implementation in which contains a ComboBox with several ComboBoxItems bound to commands. I can bind to the Name, and Text properties of the command just fine but have no way of binding the ComboBoxItem's IsEnabled property to the result of a Command's CanExecute method because it is a method. Is there some synt...

Binding a Style DataTrigger to a custom ICommand's status property

I have a custom implementation of WPF's ICommand, that executes its bindings in a BackgroundWorker, so that the UI stays responsive. I would like to display a custom effect while the bindings are being executed. For now, the effect is simplified to setting command source's IsEnabled property to False. Later, our designer will come up wi...

WPF MenuItem ViewModel Command

Hi, I am fairly new to WPF and am struggling a little with a scenario. I have a menu which has menu items. When one of these menu items gets clicked a method needs to be called that will do something based upon the text displayed associated with that menu item. So for example, the menu item's content was "test" so I would need to do som...

Command parameter access in view model

Hi Everyone I am creating a user control in MVVM. I have a datagrid in my user control.When i click a button in the user control i want to pass the parameters as selected items in the datagrid. I have declared the two controls(datagrid and button in two different data template) now when i use command parameter for the button and specif...

WPF Command parameter

Hi Everyone I am creating a user control in MVVM. I have a datagrid in my user control.When i click a button in the user control i want to pass the parameters as selected items in the datagrid. I have declared the two controls(datagrid and button in two different data template) now when i use command parameter for the button and specify...

Problem using WPF Commands with Canvas

Hi, I am having a custom canvas derived from Canvas. It contains few ApplicationCommands like New/Open/Save etc. added like this - this.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, New_Executed, New_Enabled)); New_Enabled always returns true. This control is used in a wpf project having a menu bar; New/Open/Save ...

CommandManager Executed Events don't fire for custom ICommands

The WPF CommandManager allows you to do the following (pseudo-ish-code): <Button Name="SomeButton" Command="{Binding Path=ViewModelCommand}"/> And in the code-behind: private void InitCommandEvents() { CommandManager.AddExecutedEventHandler(this.SomeButton, SomeEventHandler); } The SomeEventHandler never gets called. To me thi...

WPF key gesture PageDown shows up as Next in Menu Item.

I've setup a custom command with PageDown as the key gesture, but for the MenuItem that is bound to that command the gesture shows up as "Next". The problem is that I have commands that use PageUp, Home, and End for related tasks and they all show up as expected for their MenuItems. Is there some way to make the MenuItem show "PageDown...

How can I execute a command binding on MouseEnter of a StackPanel in WPF?

I'm using MVVM. <ItemsControl ItemsSource="{Binding AllIcons}" Tag="{Binding}"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <Label HorizontalAlignment="Right">x</Label> <Image Source="{Binding Source}" Height="100" Width="100" /> <Label HorizontalAlignm...

Retrieving CommandTarget during the Executed phase

How can I retrieve the CommandTarget in the Executed callback of a RoutedCommand? Thanks. Edit: adding a verbose sample Commands class: static class Commands { public static readonly RoutedCommand MyCommand = new RoutedCommand(); } XAML code <Window.CommandBindings> <CommandBinding Command="{x:Static BasicWpfCommanding:Command...

WPF SimpleCommand possible with generics?

I am using this code to make a Simple Command: public class SimpleCommand : ICommand { public Predicate<object> CanExecuteDelegate { get; set; } public Action<object> ExecuteDelegate { get; set; } #region ICommand Members public bool CanExecute(object parameter) { if (CanExecuteDelegate != null) ...