ItemsControl button click command

后端 未结 4 2070
礼貌的吻别
礼貌的吻别 2021-02-07 21:32

I need some quick help which is a road blocker for me now. I have Button in ItemsControl and I need to perform some task on Button click. I tried addin

4条回答
  •  佛祖请我去吃肉
    2021-02-07 22:20

    If your ViewModel has a property of type ICommand you can bind the Button's Command property to that:

    XAML:

    
       

    C#:

    public sealed class FooViewModel
    {
      public ICommand DoBarCommand
      {
        get;
        private set;
      }
      //...
      public FooViewModel()
      {
         this.DoBarCommand = new DelegateCommand(this.CanDoBar, this.DoBar);
      }
    }
    

提交回复
热议问题