Questions tagged [icommand]

Interface for MVVM scenarios in Silverlight and WPF to bind commands from models to controls (Buttons).

icommand
95 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
56 votes
1 answer
3k views

Unit-Test project fails to build after installing .NET 4.5

I have a WPF solution in .NET 4.0 that includes a Unit Test project which tests the different commands used in the ViewModels. Everything was working fine, but then I installed .NET 4.5 and VS2012. ...
atiyar's user avatar
  • 8,042
7 votes
1 answer
3k views

MVVM Call Command from CommandBinding

I wanted to bind a CommandBinding to a ViewModel ICommand, this way, when the user hits Delete I can trigger my ViewModel's delete logic. The only way I know how to do it is in code behind, with this:...
Michel Feinstein's user avatar
5 votes
0 answers
197 views

Does WPF still leak on Custom ICommand implementations?

Before .Net 4.5, WPF controls used to leak on custom ICommand implementations that did not use a weak event pattern because they did not unsubscribe from the CanExecuteChanged event of the interface. ...
Wilhelm's user avatar
  • 1,886
3 votes
1 answer
2k views

WPF ICommand CanExecute(): RaiseCanExecuteChanged() or automatic handling via DispatchTimer?

I'm trying to determine the best way to cause ICommands' CanExecute() to be reflected in the UI. I understand that the Dispatcher is the WPF (engine?) that handles UI drawing, and that by default, ...
Justin Shidell's user avatar
2 votes
0 answers
1k views

WPF how to bind to the ICommand.CanExecute()

Basicaly I am facing very similar problem to the question WPF - how to hide menu item if command's CanExecute is false?, the accepted answer uses a clever workaround to bind to the IsEnabled instead ...
wondra's user avatar
  • 3,421
2 votes
0 answers
1k views

WPF: can't pass System.Int32 as CommandParameter

I have a Button with an attached Command: <Button Command="{Binding Path=command}"> <Button.CommandParameter> <s:String>1</s:String> </Button....
undermind's user avatar
  • 1,819
2 votes
1 answer
331 views

Raise context menu command's CanExcute while open the context menu

Can Execute of a ICommand while a Context menu open With the continuation of the above query, Still its not able to achieve. Is there any way to raise context menu command's CanExcute while open ...
Sankarann's user avatar
  • 2,645
2 votes
1 answer
652 views

Where can I find the CommandTarget?

I am still making experiences with Commands and RoutedEvents. Without using RoutedCommands, I try to realize a ver simple program. Here is my Command class: public class ColorChanger : ICommand { ...
CodeCannibal's user avatar
2 votes
2 answers
79 views

ViewModel in Class project

I'm building a WPF application which is based on the MVVM pattern. Later on we are going to build a Silverlight application of the same type, and also a Web application. I want to use my ...
Peter Larsson's user avatar
1 vote
0 answers
13 views

MVVM AsyncExecute causing lag

AsyncExecute method causing lag in my treeview application when I am expanding a branch. Important parts of my TreeView public DirectoryItemViewModel(string fullPath, DirectoryItemType type, long size)...
Palamar66's user avatar
  • 222
1 vote
3 answers
3k views

Blazor - How to execute the form submit in Button click using ICommand

How to execute the form submit in Button click using ICommand How to pass parameter in ICommand execute @using System.Windows.Input <button @onclick="buttonClick"> Blazor Button</...
M K's user avatar
  • 1,981
1 vote
1 answer
603 views

Xamarin Forms Command always null in custom control

I try to create a usercontrol. The user control will be a Button to show loader. I try to pass a binded command from my page to my control My XAML PAge is: <sharedviews:...
dalton5's user avatar
  • 925
1 vote
0 answers
1k views

How correctly implement ICommand in WPF using MVVM pattern?

I`m trying to do a simple WPF application using MVVM pattern. I wrote a class implementing ICommand interface: public class RelayCommand : ICommand { private Action<object> execute; ...
Николай Деркач's user avatar
1 vote
0 answers
239 views

Binding to existing Command from other location causes Data Error: 2

I have app, where some controls can 'publish' certain keybinding which in turn appears in context help, for example a button publishes F5 a keybinding: <Button Name="PublishKeybinding" Content="...
wondra's user avatar
  • 3,421
1 vote
1 answer
47 views

In which context ICommand and Local:Mvx are prefered

I'm developing an Android application using Xamarin and MvvmCross. As seen in the layout posted at the bottom of this question I have a TextView and a Button. I want to achieve the following things: ...
user10776303's user avatar
1 vote
0 answers
65 views

UWP ICommand parameter always null

when trying to execute an ICommand, it always throws an exception due to the parameter being null. When I manually print the variable being passed to ICommand with Debug.WriteLine, it works perfectly....
zirr's user avatar
  • 69
1 vote
2 answers
57 views

shifting code of code behind to viewmodel in wpf

Here is my code-behind: private void Button_Click(object sender, RoutedEventArgs e) { foreach (FrameworkElement fe in canvas.Children) { double ...
ConfuseD's user avatar
1 vote
1 answer
744 views

Can't set default value for ICommand of an DependencyProperty

I want to call an UserControl's Command from any viewmodel. I tried to bind to the Command in my view but it didn't work. (I don't have enough reputation to post images, so here is a link to the ...
U. Bulle's user avatar
  • 1,085
1 vote
0 answers
691 views

How can I use MVVM light to execute a Command on a text box text change event

I have installed MVVMLIGHT but still somehow I can't access EventToCommand property even after adding the reference files and using the namespaces in xaml file xmlns:i="http://schemas.microsoft....
Ivan D'souza's user avatar
1 vote
0 answers
193 views

NotifyPropertyChanged, view only updates when event bound to command

I am still fairly new to c# and WPF so perhaps this is expected but I find it strange and I can't seem to get around it. I have a window with an area to input information about an event and a submit ...
chris's user avatar
  • 132
1 vote
0 answers
861 views

WPF devexpress datagrid - CanExecute is not refreshed

I'm using devexpress datagrid to build my wpf application. I've very simple gird with 2 columns. Second column contains buttons with plus sign. Buttons are binded to Command in ViewModel (with ...
rraszewski's user avatar
  • 1,135
1 vote
1 answer
114 views

How to make button bound to ICommand enable/disable when text changes, as opposed to losing focus of TextBox

I have a Windows Store XAML app with a "Save" button, which points to an ICommand property in my ViewModel. <Button Content="Save" Command="{Binding DataContext.SaveNewNote, ElementName=grid, ...
Robert Seder's user avatar
  • 1,410
1 vote
2 answers
576 views

Windows Phone - Binding TextBox or other control to CommandParameter of Button

I'm making my first steps into using Commands (by implementing the ICommand interface) in my Windows Phone applications. Now I've run into a problem I can't seem to figure out. I'm binding a control, ...
Kaj's user avatar
  • 333
1 vote
2 answers
3k views

Executing command in another viewmodel?

I have a custom "DateRangeSelector" control derived from ComboBox. This is a drop-down control with the following filters: 1. Today 2. Next three days 3. Next three weeks 4. Custom Range(Allows the ...
sandy's user avatar
  • 646
1 vote
0 answers
105 views

DataGridCellTemplate bound to ViewModel command

for each cell in this column i want to bind a command from my view model , on each can execute of that command i wan't to send the "Entity" property of each item in my items source . DataGrid : ...
eran otzap's user avatar
  • 12.4k
1 vote
1 answer
840 views

mvvm with prism: setting view from menu item

I am new to wpf world. I have a context menu in the shell as below: <ContextMenu> <MenuItem Header="Login" Command="{Binding ...
Victor Mukherjee's user avatar
1 vote
1 answer
744 views

Can Execute of a ICommand while a Context menu open

A Control has its ContextMenu and its MenuItem is bound to an ICommand. ICommand's Can Execute has some code to enable and disable the MenuItem. This hits while loading and checks for Can Execute but ...
Sankarann's user avatar
  • 2,645
1 vote
1 answer
1k views

MvvmCross, Xamarin Studio and ICommands

My issue was born in Does MvvmCross work in Xamarin Studio?. MvvmCross works fine in Visual Studio. However, I've been mandated to deploy this corporately using Xamarin Studio which is what their ...
Bryan Weidman's user avatar
1 vote
1 answer
399 views

How to continue routing with DelegateCommand in WPF

The KeyBindings in my application are stealing key down messages when I try to use the textbox. So for example: <ribbon:RibbonWindow.InputBindings> <KeyBinding Command="{Binding Review....
Patrik's user avatar
  • 1,316
1 vote
1 answer
418 views

Tunneling Commands

I have several user controls which are instantiated in a ListBox. I have a button in my Window which raises NavigationCommands.Refresh, and a CanExecute handler to allow it to execute: <Window....
Echilon's user avatar
  • 10.1k
1 vote
2 answers
475 views

Simplifying ICommand/RelayCommand in a MVVM approach

I'm pushing myself to make the applications I write simpler, and I've taken some steps to do that, but I'm left with an interesting problem that doesn't at all feel like it would be unique to me. I'm ...
Andrew's user avatar
  • 97
0 votes
1 answer
33 views

DataGrid Context Menu Not Binding Properly

I have a DataGrid to which I am trying to add a ContextMenu with a command binding. The ContextMenu is defined like so: <DataGrid Grid.Row="6" Grid.Column="0" Grid.ColumnSpan=&...
Dominick's user avatar
  • 444
0 votes
0 answers
51 views

Navigation command works when called by button but not when called programmatically

I have a WPF app which has two User Controls. On one user control, I have a list of buttons which are all binded to a command that changes the ViewModel from that user control to the other, with a ...
Ethan Shoe's user avatar
0 votes
1 answer
149 views

Dependency Property command's CanExecute() not updating

I have a user control and within I defined the following property: public string MyProperty { get { return (string)GetValue(MyPropertyProperty); } set { SetValue(MyPropertyProperty, value);...
Anno's user avatar
  • 831
0 votes
1 answer
200 views

HttpClient.GetAsync not re-enabling the button MVVM

Solved: See below. Update: This fails on the HttpClient.GetAsync. It's like a "Task Finished" event isn't listened to. I'm suspecting a threading problem. It manifests itself as the ...
Ray's user avatar
  • 425
0 votes
1 answer
122 views

If dependency property is true, then ICommand property should execute

Ok, I have the custom control with its style and the view model with the ICommand property in the different files. CustomControl.cs public class CustomButtons: Control { public static readonly ...
Manav Mehta's user avatar
0 votes
2 answers
126 views

Disable CanExecute on switching views

I have a static property which tracks property changes in my viewmodels: public static class Global { public static int Warning { get { return _warning; } set { _warning = value; ...
Lucy82's user avatar
  • 672
0 votes
0 answers
33 views

Add UIElement to the MainWindow with ICommand C#

I would like to add dinamically UIElement through ICommand. It is working fine with EventHandler but when I try to do the same using ICommand the UIElement is invisible however it seams the stackpanel ...
Milán's user avatar
  • 1
0 votes
0 answers
371 views

Carousel View in Xamarin forms not responding to Image button in the view

I cannot get the image buttons to move the carousel image to the next in the list. when I click the imagebutton and step through the code the Position is changing properly, but does not move the ...
marcusC's user avatar
  • 11
0 votes
1 answer
1k views

Passing a parameter to RelayCommand

I'm experimenting with the ICommand and RelayCommand constructs. Looking around, I've put together the following code: public class RelayCommand : ICommand { private Action<object> ...
Giovanni Nieddu's user avatar
0 votes
0 answers
70 views

Is there a way to be notified when an ICommand is executed?

Here is my code: var viewModel = factory.Create(); var commandBinding = new CommandBinding(viewModel.Command, (target, e) => { ...
PlaTyPuS's user avatar
  • 385
0 votes
1 answer
1k views

How to get property and call command from different ViewModel with mvvm pattern

I have a ViewModel with all the properties that i will need in every sub ViewModel. It's the first time i try to split commands and viewmodel to multiple files. Last time everything was in the same ...
MoneyMaker's user avatar
0 votes
0 answers
118 views

.Net C# Dependency Injection resolve ICommands same type

I have a class with many ICommands in the constructor parameters. var classWithManyCommands = new ClassWithManyCommands(new AddItemsCommand(new StringService()), ...
TomatenSalat's user avatar
0 votes
0 answers
60 views

Send Text value from 2 Labels using Command inside BindableLayout

I'm working with MVVM and I have a bindablelayout like this: <StackLayout Margin="20" BindableLayout.ItemsSource="{Binding MyApartments}" > <BindableLayout.ItemTemplate> &...
Herb's user avatar
  • 129
0 votes
1 answer
88 views

Validating Grid Rows on button click using custom ICommand implementation - WPF

I want to validate my DataGrid rows for errors, and if there are any errors present then the 'Save' button should be disabled or at least there should be some message saying there are errors. After ...
Nicolas's user avatar
  • 2,346
0 votes
0 answers
137 views

How to use MultiBinding in WPF

I would like to pass two text parameters when a button is clicked. I used MultiBinding and that partially works but something's not quite right yet. Converter: public object Convert(object[] values,...
Advertajment's user avatar
0 votes
1 answer
350 views

Unit testing ICommand.CanExecute when using CommandManager

(Part of) my ICommand implementation is: public void RaiseCanExecuteChanged() { CommandManager.InvalidateRequerySuggested(); } public event EventHandler CanExecuteChanged ...
eriksmith200's user avatar
  • 2,179
0 votes
2 answers
2k views

WPF MVVM - Simple Binding Button with Textbox (Icommand)

What I'm trying to do is: when the textbox contains the value "123" it should enable the button and allow me to click it. Solution Image & View Image I can not find a way to trigger the Button ...
UnholyHimura's user avatar
0 votes
0 answers
465 views

MRU Menu with Fluent.Ribbon - Can't wire Command to ModelView

I'm new to WPF and am trying to build an MRU (most recently used items) menu with the Fluent.Ribbon library. Some digging in example code and the internet lead me to this point where I can generate ...
Kempeth's user avatar
  • 1,926
0 votes
1 answer
129 views

ICommand Xamarin Forms

I have a strange issue of getting null exception. I created class that implements ICommand interface, I have two methods. public void Execute(object parameter) { NavigateAsync(); } private ...
Eldlabs's user avatar
  • 543