I have a Button
that closes my window when it's clicked:
<Button x:Name="buttonOk" IsCancel="True">Ok</Button>
That's fine until I add a Command
to the Button
i.e.
<Button x:Name="buttonOk"
Command="{Binding SaveCommand}"
IsCancel="True">Ok</Button>
Now it doesn't close presumably because I am handling the Command
. I can fix this by putting an EventHandler
in and calling this.Close()
i.e.
<Button x:Name="buttonOk"
Click="closeWindow"
Command="{Binding SaveCommand}"
IsCancel="True">Ok</Button>
but now I have code in my code behind i.e. the method SaveCommand
. I am using the MVVM pattern and SaveCommand
is the only code in my code behind.
How can I do this differently so as not to use code behind?
See Question&Answers more detail:os