private void _CloseParent() { var window = WPFHelper.GetParent(this, typeof(Window)) as Window; if (window != null) { window.Close(); } else { Debug.Assert(false, "Button must be hosted in a window."); } }