Drop this behavior on a button or any other UI Element to run a command when the button is clicked or the left mouse button is pressed.
The behavior accepts a Message and Caption and will optionally display a confirmation dialog before running the command.
This I very useful if you want to ask the user “are you sure” questions without having to display modal dialogs from the View Model.
In WPF you could use the Preview tunneling events to make it a bit nicer.
(Look mom, I made a messagebox. :-) Sometimes it's the how, not the what)
<Confirm:Confirm IsConfirm="{Binding ElementName=checkBoxConfirm, Path=IsChecked}" Command="{Binding Path=ButtonCommand}" CommandParameter="{Binding ElementName=textBoxParameter, Path=Text}" ConfirmMessage="Are you sure you want to fire the command?" ConfirmCaption="Question" ></Confirm:Confirm>
Download the source: ConfirmCommandBehavior.zip (38.69 kb)
Tags: mvvm, silverlight, wpf