relaycommand

XAML - MenuFlyoutItem attached to a ListView doesn't work in WP8.1

荒凉一梦 提交于 2019-12-02 18:07:43
问题 I develop an Universal app that uses the MVVM-Lght toolkit . On a page, I show a list of comments. I would like that an user could add a new comment, and edit or delete its existing comments. For adding new comment, I use an AppBarButton on the CommandBar and it works fine. For editing and deleting the existing comments, I would like to display a MenuFlyout that offers 2 items: " edit " and " delete ". I can display the MenuFlyout but nothing happens when I click on its items... Here is my

XAML - MenuFlyoutItem attached to a ListView doesn't work in WP8.1

隐身守侯 提交于 2019-12-02 10:42:16
I develop an Universal app that uses the MVVM-Lght toolkit . On a page, I show a list of comments. I would like that an user could add a new comment, and edit or delete its existing comments. For adding new comment, I use an AppBarButton on the CommandBar and it works fine. For editing and deleting the existing comments, I would like to display a MenuFlyout that offers 2 items: " edit " and " delete ". I can display the MenuFlyout but nothing happens when I click on its items... Here is my concerned xaml code: <ListView x:Name="myCommentaires" ItemsSource="{Binding Comments}"

Are there any performance implications with CanExecuteCommand?

自作多情 提交于 2019-11-30 21:16:10
What are the performance implications of using the CanExecuteCommand of the ICommand object. Is the method executed over and over again? I need to iterate through a collection of about 200 objects based on which its decided whether the button bound to the Command should be enabled? Does the CanExecuteCommand get executed repeatedly which will make my application slow The ICommand interface is the following: public interface ICommand { // two methods bool CanExecute(object parameter); void Execute(object parameter); // one event event EventHandler CanExecuteChanged; } The CanExecuteChanged

Are there any performance implications with CanExecuteCommand?

瘦欲@ 提交于 2019-11-30 05:05:12
问题 What are the performance implications of using the CanExecuteCommand of the ICommand object. Is the method executed over and over again? I need to iterate through a collection of about 200 objects based on which its decided whether the button bound to the Command should be enabled? Does the CanExecuteCommand get executed repeatedly which will make my application slow 回答1: The ICommand interface is the following: public interface ICommand { // two methods bool CanExecute(object parameter);

CanExecute on RelayCommand<T> not working

喜夏-厌秋 提交于 2019-11-30 02:01:48
问题 I'm writing a WPF 4 app (with VS2010 RC) using MVVM Light V3 alpha 3 and am running into some weird behaviour here... I have a command that opens a Window , and that Window creates the ViewModel and so on - nothing weird there. In that Window I have some RelayCommand s, for example: CategoryBeenSelected = new RelayCommand(() => OnCategoryUpdate = true); Nothing weird again - it works as I expected. The problem is that I cannot have a CanExecute method / lambda expression with a generic

Passing event args and sender to the RelayCommand

感情迁移 提交于 2019-11-29 09:36:49
How do you get event sender when using RelayCommand? This is one of those pain-in-the-%¤# answers where I don't actually answer your question, but instead lecture you about what you should be doing differently. So, sorry about that. Here goes: If you find yourself in a position where you need to get at the sender object in your viewmodel, then you should probably do something different. By referencing, say, a Button or a ListBox in your viewmodel you have made that viewmodel aware of UI concepts that it should not know anything about. My suggestion is to instead hook up to the event in the

How do you bind a command to a MenuItem (WPF)?

喜欢而已 提交于 2019-11-29 08:56:30
问题 Here is my code from the View.xaml.cs: private RelayCommand _closeCommand; public ICommand CloseCommand { get { if (_closeCommand == null) { _closeCommand = new RelayCommand(param => this.OnClose()); } return _closeCommand; } } public void OnClose() { Close(); } And here is some code from my View.xaml: <Window.ContextMenu> <ContextMenu> <MenuItem Name="menuItem_Close" Header="Close" Command="{Binding CloseCommand}" /> </ContextMenu> </Window.ContextMenu> When I run the program and select the

WPF command binding with input validation - how to enable the “save” button only if all input is valid

时光总嘲笑我的痴心妄想 提交于 2019-11-28 11:08:40
问题 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 IDataErrorInfo public string Error { get { return this[null]; } } To my understanding, Error should be empty if all validated inputs pass validation, so I pass this as my CanExecute method return !string.IsNullOrEmpty(Error); But, my "save" button never gets enabled. My gues is that CanExecuteChanged

Implementing “close window” command with MVVM

 ̄綄美尐妖づ 提交于 2019-11-27 20:23:51
So my first attempt did everything out of the code behind, and now I'm trying to refactor my code to use the MVVM pattern, following the guidance of the MVVM in the box information. I've created a viewmodel class to match my view class, and I'm moving the code out of the code behind into the viewmodel starting with the commands. My first snag is trying to implement a 'Close' button that closes the window if the data has not been modified. I've rigged up a CloseCommand to replace the 'onClick' method and all is good except for where the code tries to run this.Close() . Obviously, since the code

What is the actual task of CanExecuteChanged and CommandManager.RequerySuggested?

假装没事ソ 提交于 2019-11-27 06:41:05
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 { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } I can't understand two things: what does the CanExecuteChanged event do? what does the CommandManager.RequerySuggested do? The above code is from the RelayCommand Class from here . CanExecuteChanged notifies any command sources (like a Button or MenuItem ) that are bound to that ICommand that the value returned by