private void close_btn_Click(object sender, RoutedEventArgs e) { Window win = (Window)((FrameworkElement)sender).TemplatedParent; var setting = WindowTheme.GetTheme(win); if (setting == null || setting.ExitCommand == null) { win.Close(); } }
private void min_btn_Click(object sender, RoutedEventArgs e) { Window win = (Window)((FrameworkElement)sender).TemplatedParent; var setting = WindowTheme.GetTheme(win); if (setting == null || setting.MinButton == Visibility.Visible) { win.WindowState = WindowState.Minimized; //设置窗口最小化 e.Handled = true; } }
private void max_btn_Click(object sender, RoutedEventArgs e) { Window win = (Window)((FrameworkElement)sender).TemplatedParent; var setting = WindowTheme.GetTheme(win); if (setting == null || setting.MaxButton == Visibility.Visible) { if (win.WindowState == System.Windows.WindowState.Maximized) { win.WindowState = System.Windows.WindowState.Normal; return; } win.WindowState = System.Windows.WindowState.Maximized; e.Handled = true; } }
/// <summary> /// 设置一个对象的主题属性 /// </summary> /// <param name="dpo"></param> /// <param name="value"></param> public static void SetTheme(DependencyObject dpo, WindowTheme value) { dpo.SetValue(ThemeProperty, value); }