当前位置: 首页>>代码示例>>C#>>正文


C# Button.SetCommandParameter方法代码示例

本文整理汇总了C#中System.Windows.Forms.Button.SetCommandParameter方法的典型用法代码示例。如果您正苦于以下问题:C# Button.SetCommandParameter方法的具体用法?C# Button.SetCommandParameter怎么用?C# Button.SetCommandParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.Button的用法示例。


在下文中一共展示了Button.SetCommandParameter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssignCommandToButton

        public void AssignCommandToButton()
        {
            CommandProvider.OnClickCount = 0;
            TestViewModel viewModel = new TestViewModel();
            using(var button = new Button()) {
                button.SetCommand(viewModel.TestCommand);
                Assert.That(viewModel.TestCommandExecuteCount, Is.EqualTo(0));

                button.PerformClick();
                Assert.That(viewModel.TestCommandExecuteCount, Is.EqualTo(1));
                Assert.That(viewModel.ExecuteParameter, Is.Null);
                Assert.That(viewModel.CanExecuteParameter, Is.Null);
                Assert.That(CommandProvider.OnClickCount, Is.EqualTo(1));

                button.SetCommand(null);
                button.PerformClick();
                Assert.That(viewModel.TestCommandExecuteCount, Is.EqualTo(1));
                Assert.That(CommandProvider.OnClickCount, Is.EqualTo(1));

                viewModel.CanExecuteTestCommand = false;
                button.SetCommand(viewModel.TestCommand);
                button.PerformClick();
                Assert.That(viewModel.TestCommandExecuteCount, Is.EqualTo(1));
                Assert.That(CommandProvider.OnClickCount, Is.EqualTo(1));

                viewModel.CanExecuteTestCommand = true;
                button.SetCommandParameter("param");
                button.PerformClick();
                Assert.That(viewModel.TestCommandExecuteCount, Is.EqualTo(2));
                Assert.That(viewModel.ExecuteParameter, Is.EqualTo("param"));
                Assert.That(viewModel.CanExecuteParameter, Is.EqualTo("param"));
                Assert.That(CommandProvider.OnClickCount, Is.EqualTo(2));
            }
        }
开发者ID:VitalyTVA,项目名称:WinMVVM,代码行数:34,代码来源:CommandProviderTests.cs

示例2: UpdateIsEnabledOnSetParameter

 public void UpdateIsEnabledOnSetParameter()
 {
     var command = new DelegateCommand<string>(o => { }, o => string.IsNullOrEmpty(o));
     using(var button = new Button()) {
         button.SetCommand(command);
         Assert.That(button.Enabled, Is.True);
         button.SetCommandParameter("x");
         Assert.That(button.Enabled, Is.False);
         button.SetCommandParameter(null);
         Assert.That(button.Enabled, Is.True);
         button.SetCommandParameter("x");
         Assert.That(button.Enabled, Is.False);
         button.SetCommand(null);
         Assert.That(button.Enabled, Is.True);
         button.SetCommand(command);
         Assert.That(button.Enabled, Is.False);
     }
 }
开发者ID:VitalyTVA,项目名称:WinMVVM,代码行数:18,代码来源:CommandProviderTests.cs

示例3: TwoWayBindingForAttachedProperty

        public void TwoWayBindingForAttachedProperty()
        {
            var viewModel = new TestViewModel() { };
            using(var button = new Button()) {
                button.SetDataContext(viewModel);

                PropertyEntry<object> entry = CommandProvider.CommandParameterProperty.GetPropertyEntry(button);

                Assert.That(entry.ChangedSubscribeCount, Is.EqualTo(0));
                button.SetBinding(CommandProvider.CommandParameterProperty, new Binding(() => viewModel.StringProperty, BindingMode.TwoWay));
                Assert.That(entry.ChangedSubscribeCount, Is.EqualTo(1));

                Assert.That(button.GetCommandParameter(), Is.Null);
                button.SetCommandParameter("test");
                Assert.That(viewModel.StringProperty, Is.EqualTo("test"));

                button.ClearBinding(CommandProvider.CommandParameterProperty);
                Assert.That(entry.ChangedSubscribeCount, Is.EqualTo(0));
                Assert.That(viewModel.StringProperty, Is.EqualTo("test"));
                Assert.That(button.GetCommandParameter(), Is.Null);

                viewModel.StringProperty = "test2";
                Assert.That(button.GetCommandParameter(), Is.Null);

                button.SetCommandParameter("test3");
            }
        }
开发者ID:VitalyTVA,项目名称:WinMVVM,代码行数:27,代码来源:BindingOperationsTests.cs


注:本文中的System.Windows.Forms.Button.SetCommandParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。