WPF 创建无边框的圆角窗体

无边框窗体

在正常窗体上,将AllowsTransparency属性设置为True后,系统会自动将WindowStyle属性也设置为None

设置成无边框窗体后,将无法通过鼠标左键拖拽移动窗体,需要在窗体的MouseDown事件中调用DragMove()方法

1         private void Window_MouseDown(object sender, MouseButtonEventArgs e)
2         {
3             if (e.LeftButton == MouseButtonState.Pressed)
4             {
5                 DragMove();
6             }
7         }

窗体圆角透明

接着可以添加一个Style,利用Border元素实现窗体的圆角和透明

 1     <Window.Style>
 2         <Style TargetType="Window">
 3             <Setter Property="Template">
 4                 <Setter.Value>
 5                     <ControlTemplate TargetType="Window">
 6                         <Border Background="White" CornerRadius="15" Opacity="0.8">
 7                             <ContentPresenter/>
 8                         </Border>
 9                     </ControlTemplate>
10                 </Setter.Value>
11             </Setter>
12         </Style>
13     </Window.Style>

其中:

BorderThickness用来表示窗体边框的粗细程度

BorderBrush用来表示窗体边框的颜色

CornerRadius表明窗体四个角的弯曲度

调整完成后便可以添加控件,构建窗体了

 

 

 

*** |  以上内容仅为学习参考、学习笔记使用  | ***

 

posted @ 2021-09-11 21:22  Mr.Cat~  阅读(2206)  评论(0编辑  收藏  举报