commandbinding

Debugging CommandBinding's CanExecute

五迷三道 提交于 2019-12-10 11:28:20
问题 I have a user control with a Button bound to the NavigationCommands.RefreshCommand . The handler for the command is in the parent control. The handler's CanExecute looks like this: e.CanExecute = !IsConnecting; // IsConnecting is a Dependency Property For some reason, the Button will remain disabled until I click on the window. If I click the Button and get it to execute (which causes IsConnecting to temporarily be set to true) it will then disable the button correctly, but won't enable the

Multiple Command Binding

允我心安 提交于 2019-12-08 07:21:12
问题 Is it possible to bind the multiple commands to the button. I have a user control, which i am calling in my main application (parent application). I want to handle a click command on both the controls (the user control as well as on the main window). However i am only able to get one. Is there any way in which i can get this. Any help is really appreciated. Code Snippet: public class MainWindowFooterCommands { public static readonly RoutedUICommand FooterClickLocalCommand = new

WPF CommandBindings defined in one window not available in another

徘徊边缘 提交于 2019-12-08 02:48:02
问题 I have this problems where I have all these CommandBindings defined in the MainWindow, and said commands are available within that window to be used in any Button or MenuItem. The problem is that if in other windows the command binding is not available (it's always false), even if the new Window's owner is the MainWindow. You can see the problem here. Any help really appreciated. Here's the code. XAML MainWindow: <Window x:Class="ContextMenuDialogProblem.MainWindow" xmlns="http://schemas

CanExecute method going to false problem

僤鯓⒐⒋嵵緔 提交于 2019-12-07 23:33:25
Well, in our application this usually works fine. But at some point, none of the CanExecute methods fire (even if I explicitly call CommandManager.InvalidateRequerySuggested(), the CanExecute methods don't run). Anyway, despite the fact that they don't run, they all get set to false, so every button, menu item, etc, bound to a CommandBinding, gets disabled until I click the MainWindow. Now, I suspect another Window causing this, when we do a certain action, a Window pops up, and then after the next action, all the buttons become disabled, without going through the CanExecute method. Has anyone

Multiple parameters with Command binding

社会主义新天地 提交于 2019-12-07 16:10:33
问题 I have a textblock with command binding and using Prism library. this is the XAML parth: <TextBlock Margin="0,10,0,0">SocialSecurityNumer:</TextBlock> <TextBox Name="SSNText" GotFocus="TextBox_GotFocus" Text="{Binding SSN, UpdateSourceTrigger=PropertyChanged}" Margin="0,3,0,0"/> And this is the ViewModel behind: public FindViewModel() { var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>(); FindCommand = new DelegateCommand( () => eventAggregator.GetEvent

CommandBinding question. How to enable command button

佐手、 提交于 2019-12-07 12:02:58
问题 My code is here>> public class Player:INotifyPropertyChanging { string addressBar; public string Url { get { return addressBar; } set { addressBar = value; OnPropertyChanged("Url"); } } public Regex regVillage = new Regex(@"\?doc=\d+&sys=[a-zA-Z0-9]{2}"); RelayCommand _AddAttackTask; public ICommand AddAttackTask { get { if (_AddAttackTask == null) { _AddAttackTask = new RelayCommand(param => { }, param => this.CanAttack); } return _AddAttackTask; } } public Boolean CanAttack { get{ if (Url =

MVVM Command Binding

人走茶凉 提交于 2019-12-07 05:32:20
问题 I'm trying to learn the MVVM pattern. The main problem I'm having is learning where I should be declaring, creating and binding command objects. 2 examples: I have a main form that acts like a switch board or main menu. Selct button 1 and View 1 is displayed, Select button 2 and view 2 is displayed. Great. Now I want to go back to the main form so I need a button on View 1 (and view 2) called "Main Menu". Where should I define the command and command handlers so that I can bind to the

Is there a difference between adding CommandBindings to a control vs using RegisterClassCommandBinding?

僤鯓⒐⒋嵵緔 提交于 2019-12-07 05:19:38
问题 Previously I had been using this.CommandBindings.Add( new CommandBinding(ApplicationCommands.Copy, this.cmdCopy_Executed, this.cmdCopy_CanExecute)) where cmdCopy_Executed is a non-static function, but I've seen folks using static MyControl() { CommandBinding binding = new CommandBinding(ApplicationCommands.Save, CommandHandler); CommandManager.RegisterClassCommandBinding(typeof(MyControl), binding); } private static void CommandHandler(object target, ExecutedRoutedEventArgs e) { MessageBox

WPF CommandBindings defined in one window not available in another

◇◆丶佛笑我妖孽 提交于 2019-12-06 13:45:22
I have this problems where I have all these CommandBindings defined in the MainWindow, and said commands are available within that window to be used in any Button or MenuItem. The problem is that if in other windows the command binding is not available (it's always false), even if the new Window's owner is the MainWindow. You can see the problem here. Any help really appreciated. Here's the code. XAML MainWindow: <Window x:Class="ContextMenuDialogProblem.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns

Execute command does not fire in resource dictionary code behind

这一生的挚爱 提交于 2019-12-06 06:12:58
I have created resource dictionary and code behind file for it. In XAML I have defined command binding and added Executed handler: <Button Grid.Row="2" Width="100" > <CommandBinding Command="Search" Executed="CommandBinding_Executed" /> </Button> Here is code behind: partial class StyleResources : ResourceDictionary { public StyleResources() { InitializeComponent(); } private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { //this is never executed } } I don't know why is command not executing when button is clicked, and also, why is button enabled when I didn't set