Questions tagged [icommand]
Interface for MVVM scenarios in Silverlight and WPF to bind commands from models to controls (Buttons).
icommand
486
questions
-1
votes
2
answers
107
views
CurrentViewModel Property Change Not Reflected in ContentControl
I am currently building an application where the user can select different pages via a collection of radio buttons. When the page is active I want the radio button to be checked as true. When the ...
0
votes
0
answers
33
views
Need help to pass Command property through RelayCommand to User Control by using a binding in WPF [duplicate]
I was asked to build a user control for a button, with icons, custom texblocks, etc.
The thing is, I need to obviously be able to pass a command for the Button, but when I try to do it with Dependency ...
0
votes
1
answer
26
views
Basic PowerShell XAML Button binding to ICommand
I have the following PowerShell script, which is nothing more than a XAML WPF GUI with a button that is supposed to show a MessageBox when clicked. It loads properly, but does nothing when clicked. ...
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.
...
-1
votes
2
answers
89
views
WPF CommandBindings, ViewModel and UserControl
I'm quite new to WPF so it would be better that I will describe the intent:
I have multiple User Controls inside the main window. Each User Control has its own buttons, that I would like to bind to ...
0
votes
1
answer
40
views
ContentDialog - What to Use For SecondaryButtonCommand
I am creating a general purpose Exception message dialog, and want to have a "Copy Error" button to copy the error text to the clipboard. I cannot figure out what to use for ...
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=&...
6
votes
4
answers
4k
views
What is the recommended way to open a new window using MVVM in WPF
Hello everyone and thanks in advance for your time.
I'm currently learning MVVM using WPF for a small Biz App that I'm writing. I have read a lot of articles about the MVVM pattern and found that one ...
-1
votes
1
answer
30
views
WPF Custom Control with buttons
I have created a WPF custom control for my application. I am now struggling to wire up the events for some of the controls in the control (ToggleButtons).
I have defined the following:
WindowHeader....
3
votes
3
answers
13k
views
Connecting mouse events with ViewModel via MouseBinding
I have a user control having some telerik controls in it. I have a coded a ViewModel where all the business logic resides.
I need to intercept the LeftClick event to know when a user clicks on the ...
0
votes
1
answer
49
views
DatePicker ICommand executed multiple times
I have a DatePicker with an ICommand which perform certain tasks. For some reason when I select a date, the VM.SetPreviousDate() method is called multiple times when the Icommand is executed (at least ...
2
votes
1
answer
6k
views
WPF command binding with input validation - how to enable the "save" button only if all input is valid
In my ViewModel I have implemented IDataErrorInfo interface (along with INotifyPropertyChanged). Input validation works as intended, I have no problems there.
I have this property as part of ...
0
votes
1
answer
135
views
Command for DatePicker in WPF project
I'm working on a WPF project using MVVM and I want to create a command for a DatePicker but I have no luck. I have this setup but it doesn't trigger the command on Date selection. What I want to do is ...
1
vote
1
answer
360
views
Why is the ICommand not triggered in my MAUI app?
At the XAML I got a button using a command:
<Button Text="Month" Command="{Binding SetMonthCommand}"/>
At the ViewModel class I implement the Command:
public ICommand ...
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 ...
2
votes
2
answers
3k
views
Why does my Command.CanExecute always return false in unit test?
My Paste command seems to work during normal execution, but in unit test the CanExecute method always returns false.
Code:
public class ViewModel
{
public CommandBindingCollection ...
39
votes
3
answers
15k
views
What is the actual task of CanExecuteChanged and CommandManager.RequerySuggested?
I got the following code from Josh Smith's MVVM tutorial.
Can anyone provide a quick explanation of what this code actually does?
public event EventHandler CanExecuteChanged
{
add { ...
1
vote
1
answer
1k
views
.NET MAUI pass picker value to ICommand
I'm a beginner with .NET MAUI and I'm trying to pass a Picker value to an Icommand, but what I can receive is only this date 01/01/1900
The Icommand is fired but the date still 01/01/1900
This is my ...
-1
votes
2
answers
308
views
C# WPF Declare an ICommand in a single line
I'm in the process of learning WPF and the MVVM design pattern. Currently the code in my ViewModel for a delete customer command looks like this:
public class vmCustomers : INotifyPropertyChanged
...
11
votes
7
answers
19k
views
C#/WPF: KeyBinding not triggering Command
I have declared <InputBindings>
<UserControl.InputBindings>
<KeyBinding Key="C" Modifiers="Ctrl" Command="{Binding CopyImageCommand}" />
<KeyBinding Key="V" Modifiers="...
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);...
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)...
17
votes
4
answers
35k
views
How to cancel window closing in MVVM WPF application
How can I cancel exiting from particular form after Cancel button (or X at the top right corner, or Esc) was clicked?
WPF:
<Window
...
x:Class="MyApp.MyView"
...
/>
<Button Content="...
-1
votes
1
answer
205
views
How to implement CanExecuteChanged on Commands which can always be executed
Let's say you want to create an ICommand that can always be executed. Then it's canExecute method should always return true. And the CanExecuteChanged event is basically not very useful. In my mind it ...
2
votes
3
answers
352
views
Which layer should contain ICommand?
In WPF, I have a ViewModel class called Malfunctions, and it has an ObservableCollection of PartMalfunctions. Typically, there are anywhere between 10 to 15 PartMalfunction objects in the ...
4
votes
2
answers
872
views
AsyncCommand CanExecute handler
I am using the @Stephen-Cleary AsyncCommand implementation in WPF (.NET 4.0) and now I am trying to find out how to specify the CanExecute handler during command definition.
Usually I create the ...
-1
votes
1
answer
175
views
wpf The relayCommand needs a constractor that takes parameter
my goal is filter a dataGrid with a textbox input, so i have textbox to filter a datagrid. for all the other commands i used one of these constractors in my **relayCommand ** as follows:
// ...
0
votes
1
answer
491
views
Relay Command CanExecute is only invoked in the viewmodels constuctor once but won't invoke again when Properties are changed
What I want to do:
When my view is loaded, one can see several textboxes that are compulsory fields(marked red). For as long as those textboxes are not filled out, the button "NEXT" is ...
0
votes
0
answers
20
views
Navigate to a new window on item click in ItemTemplate in WPF [duplicate]
I have created a Grid with ItemTemplate and now on click of any item I want user to navigate to new screen. I have added ICommand function in ViewModel for this but I am not able to handle the Command ...
0
votes
2
answers
531
views
WPF - Connect EventSetter to an ICommand
I'm looking for a solution where I double click on a DataGridRow that calls a method in my ViewModel with an ICommand.
I have this code for my DataGrid's DataGridRow style:
<DataGrid.Resources>
...
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 ...
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</...
-1
votes
1
answer
220
views
How to bind a ICommand into a Button out of DataContext?
i have a Button into a DataGrid with a DataContext (KeyValuePair).
I want to implementing a Command into this Button.
But if i use the Command="{Binding CommandoTest}" it didnt work.
I ...
0
votes
1
answer
227
views
WPF ICommands Binding
I am continuing my exploration of WPF and trying to follow MVVM with Commands.
My simple code is as follow.
MainWindow.xaml
<Window x:Class="ClickCommand.MainWindow"
xmlns="...
35
votes
4
answers
173k
views
Pass command parameter to method in ViewModel in WPF?
I am trying to pass CommandParameter to the method in my ViewModel.
How to do this?
private void Open(object sender)
{
if (sender==this.objMainWindow.btnHistory)
{
objMainWindow....
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 ...
1
vote
1
answer
317
views
React to updates on ObservableCollection
I have the following piece of code:
ReactiveCommand
.CreateFromTask(_ => GetPerson())
.Execute()
.Subscribe(x => person = x);
var canNext = person?.Friends
....
4
votes
2
answers
7k
views
ICommand CanExecuteChanged not updating
I am trying for MVVM pattern basic level and got struck at ICommand CanExecute changed. I have XAML binding as follows:
<ListBox ItemsSource="{Binding Contact.Addresses}" x:Name="...
1
vote
3
answers
5k
views
Add command property to any custom controls
I can navigate to another view with below Code. I want to use tabControl and Custom Controls for navigation but there is no Command property for binding myCommand.
so how can I bind my commands to ...
2
votes
2
answers
1k
views
CompositeCommand wait for all Child Commands to complete
In my Dialog I have a TabControl with ChildViews using Prism. For the Save Commands I'm using a CompositeCommand. Everything works as expected.
The only problem is: I want to wait for every ...
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; ...
2
votes
4
answers
2k
views
WPF: Update button if text in TextBox changes
To learn WPF Command and CommandParameter I have a small WPF application with one TextBox and one Button. Whenever the button is pressed, ICommandTest should be called with the text of the text box as ...
0
votes
1
answer
681
views
WPF - MVVM - View doesn't update when changing properties of a VM instance
I'm fairly new to MVVM and WPF so take everything what I'm saying with a grain of salt. My problem is quite complex and I've been trying to find a solution for the past day now. To no avail...
Context
...
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 ...
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 ...
0
votes
1
answer
41
views
is it possible to create an invisible xaml command always set to true?
I am working with a window and I would like to create a command that is invisible (or virtual, I am not sure about how it is called) and always checks itself (always true during runtime). This way I ...
0
votes
1
answer
129
views
WPF ObservableCollection & InotifyPropertyChanged [duplicate]
the model class represents the database. I pull the data from the database in the viewmodel and display it in the datagrid. When I change the corresponding cell in the datagrid, this change is not ...
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()),
...
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> ...
0
votes
1
answer
608
views
wpf-mvvm how can i validate my data with icommand?
I'm new to WPF development and I don't get any further with google either. I don't understand how I can validate my model data with ICommand. I understand that there are annotations and that the ...