I need to implement a custom window decorator where a Close button will behave exactly as the close or x button on all Windows applications.
Simply call the close()
function from your button:
WPF:
<Button Name="CloseButton" Content="x" Click="CloseButton_Click" />
code-behind:
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
If you would like to use MVVM architecture, then you can pass the name of your window as a Command Parameter and in the Command you can close the window.
The code would be something like this:
Button Command="{Binding MainCloseButtonCommand}"
CommandParameter="{Binding ElementName=mainWindow}"
private void performMainCloseButtonCommand(object Parameter)
{
Window objWindow = Parameter as Window;
objWindow.Close();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With