制作自定义样式的窗口

不使用windows自带的窗口样式,使用自定义的客户区,

<Window xmlns:my="clr-namespace:MiniFileTransferClient.Presentation.WPF.UILogic.ShowPanels"  x:Class="MiniFileTransferClient.Presentation.WPF.MiniFileTransferViewer"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MiniFileTransferViewer"  WindowStyle="None"  AllowsTransparency="True"
        MouseLeftButtonDown="Window_MouseLeftButtonDown"  StateChanged="Window_StateChanged" Height="530" Width="395"
        Background="Transparent">
    <Border   Height="530" Width="395"  BorderBrush="Gray" BorderThickness="0"   CornerRadius="5,5,5,5">
        <Border.Background>
            <ImageBrush ImageSource="/MiniFileTransferClient.Presentation.WPF;component/Images/zhujiemian.png"/>
        </Border.Background>
    </Border>
</Window>

其中WindowStyle="None"、AllowsTransparency="True" 、Background="Transparent"这三个属性都是要设定的。由于现在默认的非客户区没有了,按下鼠标是不能拖动窗口的,必须在设定鼠标左键按下时的情况,就有了MouseLeftButtonDown="Window_MouseLeftButtonDown" 事件对应的代码:

                private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
                {
                        this.DragMove();
                }
原文地址:https://www.cnblogs.com/goxmpx/p/3751329.html