Questions tagged [commandbinding]

Binds a RoutedCommand to the event handlers that implement the command.

201 questions
2
votes
1 answer

Command Binding to Routed Event in WPF User-control

I want to bind Viewmodel command to Usercontrol's Routed Event. Here is the detailed explanation of what I have. I have a User Control which have one Image (which shows image) and one Button at bottom (Button to remove Image). I am using a…
Hardik
  • 1,716
  • 6
  • 27
  • 41
2
votes
2 answers

How can I write a test for a WPF Command binding?

I have a "commands" class: public static class MyCommands { private static ICommand exitCommand = new RoutedCommand(); public static ICommand ExitCommand { get { return exitCommand; } } } Code-behind in MainWindow.xaml.cs: private void…
mlibby
  • 6,567
  • 1
  • 32
  • 41
2
votes
0 answers

Execute RoutedCommand from test when OriginalSource is just a dummy element

I want to raise a Command from a test. I need to simulate that a RibbonMenuItem is the OriginalSource. Unfortunately I do not have any access to the original RibbonBar and thus also not to a RibbonMenuItem. Accordingly I create a new one in my…
Em1
  • 1,077
  • 18
  • 38
2
votes
1 answer

WPF Binding FrameworkElement event to command

How can I bind a UserControl's FrameworkElement event to a view model command? I use MVVM and Prism so clear separation between the view the view-model would be nice. I'd tried multiple things, and none of them worked:
Chris Klepeis
  • 9,783
  • 16
  • 83
  • 149
2
votes
1 answer

Setting Command Bindings via XAML on PageFunction forms

If you are creating a WPF window or a WPF page, you can bind commands to functions within the XAML.
Andrew Shepherd
  • 44,254
  • 30
  • 139
  • 205
2
votes
0 answers

Is re-use of commands from the WPF command library a bad idea?

WPF provides a library of pre-defined commands (ApplicationCommands.Save, NavigationCommands.NextPage, etc.) that we can create command bindings for in our own application. I know that it is possible to create multiple command bindings for a single…
ebpa
  • 1,171
  • 1
  • 12
  • 31
1
vote
1 answer

How to do InputBindings for a DataBound ListBox?

I have a ListBox with ItemsSource bound. If anyone selects a ListBoxItem and presses Enter key, a command should be executed. How could I do this? I have ItemContainerStyle for ListBox and I cannot find a way to set InputBindings through Style. Any…
WPF Lover
  • 299
  • 6
  • 16
1
vote
0 answers

WPF ContextMenu CommandBinding disabled

I have a button and a context menu bound to the same Command, when I start the app, the button is enabled, but the context menu item isn't (as I said, they're bound to the same command). The context menu item becomes enabled only after I click the…
Carlo
  • 25,602
  • 32
  • 128
  • 176
1
vote
1 answer

Custom Command Class with WPF (without ViewModel link)

In context of : .NET Core WPF application I would like to : Create custom Command Class for what : Binding basic custom action on Button click I try lot of things but I always error generated in compilation. Can you help me to create this concept of…
miltone
  • 4,416
  • 11
  • 42
  • 76
1
vote
1 answer

Stop CommandBindings being serialised in UserControl

I have a user control that programmatically sets up its command bindings and content. I also serialise this control to XAML. I do not want the content or bindings to be serialised since I set these up. Content is taken care of by overriding: public…
GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
1
vote
1 answer

Xamarin Custom Control Binding Not Working

I created a ContentView, called Switch, to host this slider as a custom control mainly so I can reuse the on and off visual states. The ContentView contains a Label (which is there just for debugging) and a Syncfusion Switch plus some…
John Mc
  • 212
  • 2
  • 16
1
vote
1 answer

ControlTemlate Command Binding

Microsoft documentation shows how to inherit from a ControlTemplate and use a ContentPresenter. It shows how to use string properties to populate string bound items in the template. (e.g. HeaderText) It doesn't show how to do the same with…
John Mc
  • 212
  • 2
  • 16
1
vote
1 answer

ComboBox inside Button, how to pass "SelectedItem" of Combobox as CommandParameter of Button?

I am not able to access SelectedItem of Combobox that resides inside a button. I want to pass the SelectedItem as CommandParameter of the Button to my VM. Inside my VM I use MVVMLight's ICommand. What am I doing wrong?
Matt
  • 7,004
  • 11
  • 71
  • 117
1
vote
1 answer

ReactiveUI command binding + ContextMenu in resources =?

I have a ReactiveUserControl. In this I have a TreeView that uses the ContextMenus defined below. The Converter enables me to have different menus for different items types in the tree. Now what I want to do is to use the code behind to do a…
1
vote
1 answer

Execute a method in another Control using MVVM

I have built a dummy UserControl that has a method in its code-behind to display a message. I have used this control in my main window and want to execute its method when I click a Button using Commands and MVVM. Is this a good design, and if not,…
Vahid
  • 5,144
  • 13
  • 70
  • 146