What actually happens when running ApplicationCommands.Close

I think the question in the title is clear enough. What happens when i call

ApplicationCommands.Close.Execute(null,null)

from my viewmodel class.

I have a modeldialog that shows usercontrol.I has a button binding command in usercontrol that runs in viewmodel.I want to close the dialog after the command is executed. This can be done using the above command until the end of the executed event.

But I wonder if this is right. Could this cause any undesirable effect?

+4
source share
1 answer

Unfortunately this will not work.

ApplicationCommands.Close is a RoutedUiEvent that requires a CommandTarget (any IInputelement). It uses this target command to enhance routing.

You can then handle this routedevent with the command.

From the ViewModel, you can bind ApplicationCommands.Close to the Close button, and then handle the routed close event in your window.

However, you cannot call ApplicationCommands.Close.Execute(null,null) in your ViewModel after executing another command, since you do not have a CommandTarget (second zero)

There are other threads like this. How should the ViewModel close the form? which details various methods for this.

http://adammills.wordpress.com/2011/02/16/mvvm-uses-for-applicationcommands-close/

+3
source

Source: https://habr.com/ru/post/1334034/


All Articles