2 绑定command

第一步,在viewmodel声明一个ICommand对象

第二步,创建一个command调用的方法

第三步,实例化声明的ICommand对象

          private string showtext;

        public string ShowText
        {
            get { return showtext; }
            set { Set(ref showtext , value); }
        }
        public ICommand testCommand { get; set; }
        /// <summary>
        /// Initializes a new instance of the MvvmViewModel class.
        /// </summary>
        public MvvmViewModel()
        {
            ShowText = "good job!";
            testCommand = new RelayCommand(testCommandMethod);
        }

        private void testCommandMethod()
        {
            ShowText = "command work!!!!!";
        }

第四步, 在View上创建一个button,并将声明的icommand对象绑定到button上

        <Button Command="{Binding testCommand}" Margin="10,124,0,0" Height="68" VerticalAlignment="Top" HorizontalAlignment="Left" Width="257"></Button>

WPF/MVVM学习笔记(2)

相关文章:

  • 2021-07-01
  • 2022-01-01
  • 2021-09-17
  • 2021-06-01
  • 2021-05-25
  • 2021-07-01
  • 2021-10-12
  • 2021-11-13
猜你喜欢
  • 2021-08-22
  • 2022-01-29
  • 2021-11-12
  • 2022-02-22
  • 2021-11-26
  • 2021-06-08
  • 2021-06-08
相关资源
相似解决方案