icommand

Command binding to ViewModel with confirmation logic in View

眉间皱痕 提交于 2021-02-07 21:51:36
问题 Looking for the most elegant solution to bind a button command to a ViewModel ICommand property, while allowing confirmation in the View. What I would like to do: Only allow a user to click a button when he/she should When the button is clicked, ask a confirmation If comfirmed, do work in the ViewModel, otherwise cancel Do not break MVVM architecture The confirmation requirement can be fulfilled by showing a messagebox from the ViewModel. However, I don't think this is the way to go. Doesn't

WPF: Update button if text in TextBox changes

守給你的承諾、 提交于 2020-08-06 04:47:27
问题 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 parameter. This works fine. The next step is: if the text becomes too small, the button should be disabled. I use MVVMLight to implement the command. The code below is enough to call method Test whenever the button is pressed. Code so far The following works: At startup the text box gets its

AppCommand are not supported in a Windows Presentation Foundation (WPF) project

核能气质少年 提交于 2020-01-17 05:21:10
问题 I am trying to run the code from the question "Understanding ICommand implementation without MVVM" in VS2012 (Window 7) but getting errors: "AppCommand are not supported in a Windows Presentation Foundation (WPF) project" Well, what is wrong or what should I do in order to run the code from that question? MainWindow.xaml.cs: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data;

ICommand CanExecuteChanged not updating

﹥>﹥吖頭↗ 提交于 2020-01-11 09:50:42
问题 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="AddressCollections" Height="152" SelectedValue="{Binding SelectedAddress}" DockPanel.Dock="Top" /> <Button Content="Add" Command="{Binding AddAddressCommand}" DockPanel.Dock="Top" /> <Button Content="Remove" Command="{Binding DeleteAddressCommand}" DockPanel.Dock="Bottom" /> Commands: Public Class DeleteCommand

Why Are ICommand Properties Treated Specially by Bindings?

点点圈 提交于 2020-01-04 18:16:30
问题 So far, I had the impression that WPF generally looks at the actual type of an object it gets via a binding or in any other way to determine what templates, styles and representation to use. However, I am now confronted with a situation which makes it seem like WPF (also?) looks at the declared property type for some reason. This is an exemplary view model: using System; using System.Windows.Input; public class SimpleViewModel { private class MyExampleCommand : ICommand { public bool