Search code examples
c#wpfmvvmmodern-ui

Modern UI CommandBinding


I have a little problem with my modern UI application. I can'T figure out how can I run a simple Button Commmand Binding in Links Group, because i don't want show a new page . I only want run my Logout code in code behind with Command Binding.

Example what I want

Ofcourse,I know this is just an idea that does not work. I only search a possible solution.

can someone advise something?


Solution

  • Your command needs to be a property and the DataContext of where you are trying to use it needs to be set to where your property is stored (typically in a view model). If you are using the code behind you can set the data context to the window or user control (whichever it is) and have access to the property for binding purposes; however, this is a bad practice and you will benefit more from using a view model.

    So in short, create a view model with your command as a property. Set the DataContext to the view model and then bind to the property.