icommand

ICommand doesn't work

一世执手 提交于 2020-01-03 05:15:29
问题 I am starting with MVVM pattern and I have a problem with my button's command. I have a window which contains a TextBox for login and a custom PasswordBox with Password DependencyProperty for password (I know that any password should not be kept in memory, however it is only for fun, so do not be frustrated :) ) . There is also a button and I want it to be enabled if and only if the login and password are both not empty. However my command does not work properly. Here is the code: LoginWindow

ICommand doesn't work

岁酱吖の 提交于 2020-01-03 05:15:12
问题 I am starting with MVVM pattern and I have a problem with my button's command. I have a window which contains a TextBox for login and a custom PasswordBox with Password DependencyProperty for password (I know that any password should not be kept in memory, however it is only for fun, so do not be frustrated :) ) . There is also a button and I want it to be enabled if and only if the login and password are both not empty. However my command does not work properly. Here is the code: LoginWindow

Silverlight MVVM: where did my (object sender, RoutedEventArgs e) go?

风流意气都作罢 提交于 2020-01-02 10:22:22
问题 I am using commanding in my viewmodel to handle events. like for example I am handling a button click event like this: XAML <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <i:InvokeCommandAction Command="{Binding mvvmButtonclick}" /> </i:EventTrigger> </i:Interaction.Triggers> Viewmodel Code public ICommand mvvmButtonclick { get; private set; } Viewmodel Constructor code to wireup the command this.mvvmButtonclick = new ActionCommand(this.ButtonClickedEvent); Actual method in the

Silverlight MVVM: where did my (object sender, RoutedEventArgs e) go?

二次信任 提交于 2020-01-02 10:21:24
问题 I am using commanding in my viewmodel to handle events. like for example I am handling a button click event like this: XAML <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <i:InvokeCommandAction Command="{Binding mvvmButtonclick}" /> </i:EventTrigger> </i:Interaction.Triggers> Viewmodel Code public ICommand mvvmButtonclick { get; private set; } Viewmodel Constructor code to wireup the command this.mvvmButtonclick = new ActionCommand(this.ButtonClickedEvent); Actual method in the

What replaces CommandManager in WinRT?

北城以北 提交于 2019-12-31 20:39:11
问题 I'm getting started with Metro style applications (I know we're not supposed to call it Metro, but I can never remember what it's supposed to be called...), and I'm implementing a DelegateCommand class for use in MVVM. In WPF, the ICommand.CanExecuteChanged event is typically implemented like this: public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } But the CommandManager class does not exist in

Why use commands in MVVM

耗尽温柔 提交于 2019-12-31 03:55:26
问题 I'm actually learning MVVM pattern. I can't understand one thing about commands. Why use them? Why don't just use a function (in the View ) which call a ViewModel 's function? What commands provide us? Apparently they are widely used, but i can't find why. 回答1: Why use commands? Because commands provide encapsulation. You can hide any kind of complex logic inside a ICommand and you can swap the implementation whenever you need. So that your View doesn't need to know anything about your

WPF ViewModel Commands CanExecute issue

岁酱吖の 提交于 2019-12-28 13:48:49
问题 I'm having some difficulty with Context Menu commands on my View Model. I'm implementing the ICommand interface for each command within the View Model, then creating a ContextMenu within the resources of the View (MainWindow), and using a CommandReference from the MVVMToolkit to access the current DataContext (ViewModel) Commands. When I debug the application, it appears that the CanExecute method on the command is not being called except at the creation of the window, therefore my Context

Command for WPF TextBox that fires up when we hit Enter Key

六月ゝ 毕业季﹏ 提交于 2019-12-28 04:58:10
问题 It is very easy to bind Button s in WPF apps to Command s in a VIEWMODEL class. I'd like to achieve a similar binding for a TextBox . I have a TextBox and I need to bind it to a Command that fires up when I hit Enter while the TextBox is focused. Currently, I'm using the following handler for the KeyUp event, but it looks ugly... and I can't put it in my VIEWMODEL class. private void TextBox_KeyUp(object sender, KeyEventArgs e) { if (e.Key == System.Windows.Input.Key.Enter) { // your event

How to find out which button I pressed?

耗尽温柔 提交于 2019-12-24 23:48:51
问题 Picture the notification-dropdown menu from Facebook. I want to implement something similar. When clicking 'Slet', it's supposed to delete that notification from the list. private void AddNotificationsToPanel(List<Notification> notifications, StackPanel panel) { panel.Children.Clear(); foreach (var notification in notifications) { //We want every message to have text, a delete button and a postpone button //So we need a nested stackpanel: var horizontalStackPanel = new StackPanel();

Binding doesn't update when property is set inside a command

本小妞迷上赌 提交于 2019-12-24 20:12:50
问题 I am having a surprising difficulty trying to make a simple thing work, that is, setting a property in a method called by a Command bound to a Button. When I set the property in the ViewModel constructor, the correct value is properly displayed in View, but when I set this property with the command's method, the View doesn't update, although any breakpoint I create is reached (even inside RaisePropertyChanged in my ViewModelBase ). I am using vanilla RelayCommand found easily in online