icommand

Passing two command parameters on button click on WPF NET 3.5 MVVM

倖福魔咒の 提交于 2019-12-13 22:34:34
问题 I am trying to pass two ICommand parameters on button click to a method in view model. Now I am able to pass only one parameter. Code here. XAML (View) : <Button x:Name="btnAdd" Command="{Binding AddUserCommand}" CommandParameter="{Binding IDUser}"/> View Model : public string IDUser { get { return this.personalData.UserID; } set { if (this.personalData.UserID == value) { return; } this.personalData.UserID = value; OnPropertyChanged("UserID"); } } private RelayCommand addUserCommand; public

Does ICommand always requires an object as a parameter?

好久不见. 提交于 2019-12-13 06:19:42
问题 When I implement the ICommand interface, the following methods are created #region ICommand Members public bool CanExecute(object parameter) { } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { } #endregion The interesting part is public void Execute(object parameter) { } Simply because it indicates that it expects 1 parameter. What if I don't need to pass a parameter? In my ViewModel I have the following code public class DownloadViewModel : BaseViewModel

Why does my Command.CanExecute always return false in unit test?

。_饼干妹妹 提交于 2019-12-12 20:46:06
问题 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 CommandBindings { get; set; } public ICommand PasteCommand { get; set; } public ViewModel() { CommandBinding pasteBinding = new CommandBinding(ApplicationCommands.Paste, Paste, CanPasteExecute); RegisterCommandBinding(pasteBinding, typeof(ViewModel)); PasteCommand = (RoutedUICommand)pasteBinding.Command; } private

Button not enabled even after providing CommandParameter in WPF

不羁岁月 提交于 2019-12-12 12:23:55
问题 I created a button whose commandparameter is set and command using a class that implements ICommand interface. But my button is disabled. Why is that? I got this code from here: ICommand is like a chocolate cake <Window x:Class="ICommand_Implementation_CSharp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:ICommand_Implementation_CSharp" Title="MainWindow" Height="350" Width="525">

Predicate won't validate parameter correctly

家住魔仙堡 提交于 2019-12-12 03:26:57
问题 This is an additional question to my other Thread here: MVVM Navigating through different Views, I've figured out, that the problem no one solved so far (other thread). This question is related to my command's Predicate(CanExecute Method). public RelayCommand ChangePageCommand { get { return new RelayCommand(p => ChangeViewModel((BaseViewModel)p), x => x is BaseViewModel); } } public RelayCommand TestChangePageCommand { get { return new RelayCommand(p => MessageBox.Show((p is BaseViewModel)

Executing I command asynchronously

自古美人都是妖i 提交于 2019-12-11 05:17:54
问题 For the sake of simplicity I reproduced my Xamarin nUnit testing error as a console aplication and it shows the same problem that I cannot understand. So first the code that works and second the code that doesn't work. Simple console app public class Working { private MyViewModel _viewModel; public Working() { Console.WriteLine("Start"); _viewModel = new MyViewModel(); } static void Main(string[] args) { Working prog = new Working(); prog.Print(); } public void Print() { _viewModel

In which context ICommand and Local:Mvx are prefered

主宰稳场 提交于 2019-12-11 04:25:53
问题 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: Bind the OnClick listener of the button to the onClikCommand method as shown in the code below. When the onClikCommand is called I expect the value of the Text attribute of the TextView to change according to the evaluation of the if-statement. Broadcast the value of the evaluation via a

How to bind keyboard input command to main window?

不打扰是莪最后的温柔 提交于 2019-12-11 03:20:00
问题 I am relatively new to WPF Binding, and having a difficulty in binding a ICommand implemented Class which is to detect user keyboard input in the window? At first I think I need to bind it to the Window on XAML, but, it appears that Window doesn't have Command . This is my ViewModel Class public class NoteBoxViewModel { public MusicalNotation MusicalNotation { get; set; } public ICommand KeyboardHotkeyCommand { get; private set; } public bool IsSelected { get; set; } public NoteBoxViewModel()

object sender is always null in RelayCommand

不问归期 提交于 2019-12-11 02:58:04
问题 I am using RelayCommand to handle a button click, I need to get the sender parameter but it is always null, any idea why? ViewModel.cs private RelayCommand _expandClickCommand; public ICommand ExpandClickCommand { get { if (_expandClickCommand == null) { _expandClickCommand = new RelayCommand(ExpandClickCommandExecute, ExpandClickCommandCanExecute); } return _expandClickCommand; } } public void ExpandClickCommandExecute(object sender) { //sender is always null when i get here! } public bool

Can I call a command inside a command?

北慕城南 提交于 2019-12-10 22:03:40
问题 I have a closecommand defined inside my viewmodel for my dialog window. I have another command defined inside that viewmodel. Now I have that command binded to a control in my view. After performing certain command actions, I want it to call closecommand to close the window. Is that possible? 回答1: Yes. You can use a CompositeCommand that wraps both (or any number) of your other commands. I believe this is in Prism, but if you don't have access to that in your project, it isn't terribly