WPF Save/Cancel

WPF Save/Cancel

Old forum URL: forums.lhotka.net/forums/t/3399.aspx


jtnjtnjtn posted on Sunday, August 19, 2007

The default behaviour of the Save and Cancel buttons enabling/disabling based on IsDirty etc is great but I want the form to close after the user hits Save or Cancel.  Additionally I want the Close button enabled always so othat the form can be closed without changing the data.

The XAML is:
 <Button
                Command="ApplicationCommands.Save"
                CommandTarget="{Binding Source={StaticResource Country}, Path=CommandManager, BindsDirectlyToSource=True}"
                HorizontalAlignment="Left" IsDefault="True">Save</Button>
              <Button
                Command="ApplicationCommands.Undo"
                CommandTarget="{Binding Source={StaticResource Country}, Path=CommandManager, BindsDirectlyToSource=True}"
                HorizontalAlignment="Left" IsCancel="True">Cancel</Button>

I tried adding a Click event as follows:

              <Button
                Command="ApplicationCommands.Undo"
                CommandTarget="{Binding Source={StaticResource Country}, Path=CommandManager, BindsDirectlyToSource=True}"
                Click="CancelButton_Click"
                HorizontalAlignment="Left" IsCancel="True">Cancel</Button>

but the Click event fires before the Command which is no good.

Is there a way of capturing the ApplicationCommand after it has completed, testing the result and then closing the form?
Is there a way of having all of the benefits of codeless updates and modifying the behaviour of the buttns so that they do not disable based on the data?

Copyright (c) Marimer LLC