You must Sign In to post a response.
  • Category: .NET

    Enable and disable button

    How to Endble Disable command button using MVVM WPF.
  • #765811
    Hi

    btnSubmit.Enabled = true;
    btnSubmit.Enabled = false;

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #765812
    you can do it by using , By way of using the command pattern. In your view model do following code

    public class MyViewModel : ViewModel
    {
    private readonly ICommand someCommand;

    public MyViewModel()
    {
    this.someCommand = new DelegateCommand(this.DoSomething, this.CanDoSomething);
    }

    public ICommand SomeCommand
    {
    get { return this.someCommand; }
    }

    private void DoSomething(object state)
    {
    // do something here
    }

    private bool CanDoSomething(object state)
    {
    // return true/false here is enabled/disable button
    }
    }

    //In your XAML:
    < Button Command="{Binding SomeCommand}">Do Something</Button>

    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments