commandbinding

CommandBinding question. How to enable command button

混江龙づ霸主 提交于 2019-12-06 02:33:52
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 == null) return false; return regVillage.IsMatch(Url); } } } On the xaml, i have textbox and button.

Multiple parameters with Command binding

試著忘記壹切 提交于 2019-12-05 20:11:54
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<SSNChangedEvent>().Publish(SSN), () => !string.IsNullOrWhiteSpace(Kennitala) ); } public DelegateCommand FindCommand

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

蓝咒 提交于 2019-12-05 11:22:23
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.Show("Command Handled!"); } where the CommandBinding is static. Is one preferred over another? The latter

WPF CommandParameter Binding Problem

荒凉一梦 提交于 2019-12-05 10:26:23
I'm having some trouble understanding how command parameter binding works. When I create an instance of the widget class before the call to InitializeComponent it seems to work fine. Modifications to the parameter(Widget) in the ExecuteCommand function will be "applied" to _widget. This is the behavior I expected. If the instance of _widget is created after InitializeComponent, I get null reference exceptions for e.Parameter in the ExecuteCommand function. Why is this? How do I make this work with MVP pattern, where the bound object may get created after the view is created? public partial

MVVM Command Binding

拈花ヽ惹草 提交于 2019-12-05 09:22:04
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 "ShowMainMenu" command? I could create them in the View2ViewModel but then I don't have access to show the

WPF DataGrid: CommandBinding to a double click instead of using Events

邮差的信 提交于 2019-12-04 07:58:05
问题 I know how to use the MouseDoubleClick event with my DataGrid to grab the selectedvalue, but how would one go about using command bindings instead? That way my ViewModel can handle the logic. So far I have the following: <DataGrid Name="TestGrid" Grid.Row="2" Grid.ColumnSpan="2" AutoGenerateColumns="True" MouseDoubleClick="TestGrid_MouseDoubleClick" ItemsSource="{Binding Registrations}" SelectedValue="{Binding CurrentRegistration}" IsReadOnly="True" AlternationCount="2" GridLinesVisibility=

WPF DataGrid: CommandBinding to a double click instead of using Events

混江龙づ霸主 提交于 2019-12-02 18:55:00
I know how to use the MouseDoubleClick event with my DataGrid to grab the selectedvalue, but how would one go about using command bindings instead? That way my ViewModel can handle the logic. So far I have the following: <DataGrid Name="TestGrid" Grid.Row="2" Grid.ColumnSpan="2" AutoGenerateColumns="True" MouseDoubleClick="TestGrid_MouseDoubleClick" ItemsSource="{Binding Registrations}" SelectedValue="{Binding CurrentRegistration}" IsReadOnly="True" AlternationCount="2" GridLinesVisibility="None"> I want to get rid of MouseDoubleClick and replace it appropriately. No need for attached

Why DataBinding is not propagating to UserControl

回眸只為那壹抹淺笑 提交于 2019-12-01 15:02:35
This morning I asked a question here and doing a simple working sample gave me a different behavior than expected. Full working sample at GitHub . Main partial code below. In this present case, the command is never propagated to any UserControl, either if the UserControl is use directly as a child of the Window. It also not work if the UserControl is used as a DataTemplate for a ListBox ItemTemplate. I also include a hack button to fix the problem where the Command reach the UserControls. The hack come from StackOverflow . But using the hack does not explain why UserControl does not receive

WPF Routed Command with Bindings per-Tab

我的梦境 提交于 2019-12-01 13:45:00
I intended to disable and enable the Buttons outside the TabControl, just like those inside the TabItem when the current tab is changed. But the CommandBindings of the TabItem do not seem to impact "up" the visual tree. What is the right way to do this? With this XAML: <Window x:Class="WpfApplication10.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication10" Title="MainWindow" Height="350" Width="525"> <StackPanel> <Button Content="MyCommand1" Command="local:MainWindow

Why DataBinding is not propagating to UserControl

无人久伴 提交于 2019-12-01 12:08:54
问题 This morning I asked a question here and doing a simple working sample gave me a different behavior than expected. Full working sample at GitHub. Main partial code below. In this present case, the command is never propagated to any UserControl, either if the UserControl is use directly as a child of the Window. It also not work if the UserControl is used as a DataTemplate for a ListBox ItemTemplate. I also include a hack button to fix the problem where the Command reach the UserControls. The