其他分享
首页 > 其他分享> > WPF自写大小化关闭按钮的应用实例

WPF自写大小化关闭按钮的应用实例

作者:互联网

                            <Button x:Name="btnMin"
                                Content="―"
                                Style="{StaticResource MaterialDesignFlatMidBgButton}" />
                            <Button x:Name="btnMax"
                                Content="☐"
                                Style="{StaticResource MaterialDesignFlatMidBgButton}" />
                            <Button x:Name="btnClose"
                                Content="✕"
                                Style="{StaticResource MaterialDesignFlatMidBgButton}" />

Xaml代码↑

后端代码↓

            btnMin.Click += (s, e) => { this.WindowState = WindowState.Minimized; };
            btnMax.Click += (s, e) =>
            {
                if (this.WindowState == WindowState.Maximized)
                    this.WindowState = WindowState.Normal;
                else
                    this.WindowState = WindowState.Maximized;
            };
            btnClose.Click += (s, e) =>
            {
                this.Close();
            };
            ColorZone.MouseMove += (s, e) =>
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                    this.DragMove();
            };
            ColorZone.MouseDoubleClick += (s, e) =>
            {
                if (this.WindowState == WindowState.Normal)
                    this.WindowState = WindowState.Maximized;
                else
                    this.WindowState = WindowState.Normal;
            };

 界面是这样的↓

 

 

标签:自写,Normal,按钮,else,WindowState,Maximized,WPF,Click,ColorZone
来源: https://www.cnblogs.com/hack747/p/16198059.html