首先,主窗体需要设置三个按钮,同时是放大,缩小和最小化隐藏,在窗体开始加载的时候,缩小按钮是不可见的,在小的情况下不可以再小
Rect rcnormal; private void btMinWindow_Click(object sender, RoutedEventArgs e) { this.WindowState = WindowState.Minimized; } private void Button_Click(object sender, RoutedEventArgs e) { this.btnMaximize.Visibility = Visibility.Collapsed;//使最大化图标隐藏 this.btnNormal.Visibility = Visibility.Visible;//使还原图标显示 this.rcnormal = new Rect(this.Left, this.Top, this.Width, this.Height);//保存下当前位置与大小 Rect rc = SystemParameters.WorkArea;//获取工作区大小 // this.BorderThickness = new Thickness(0, 0, 0, 0);//隐藏阴影 // 经过试验,发现window最多可以比屏幕大一圈,10像素左右,再多就不能显示了 this.Left = -10;//设置位置 this.Top = -10; this.Width = rc.Width + 22; this.Height = rc.Height + 20; } private void btnNormal_Click(object sender, RoutedEventArgs e) { //this.BorderThickness = new Thickness(24, 24, 24, 24);//显示阴影 this.Left = rcnormal.Left; this.Top = rcnormal.Top; this.Width = rcnormal.Width; this.Height = rcnormal.Height; this.btnMaximize.Visibility = Visibility.Visible; this.btnNormal.Visibility = Visibility.Collapsed; } private void btnX_Click(object sender, RoutedEventArgs e) { Environment.Exit(0); }
2.xaml代码中的VIembox