我已经定制了一个无边框窗口,它是no style
and no border
,AllowsTransparency="True"
并且在这个窗口的顶部有一个矩形功能,而不是内置的标题栏。
一般情况下,拖动最大化窗口的标题栏即可恢复窗口,但在我自定义的无边框窗口中,我不知道如何实现。谁能帮我?
这是简单的代码:
<Window x:Class="WpfApplication24.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
WindowStyle="None"
AllowsTransparency="True">
<DockPanel LastChildFill="False">
<Rectangle DockPanel.Dock="Top" x:Name="DragRectangle" Height="30" Fill="#FF123456" MouseLeftButtonDown="DragRectangle_MouseLeftButtonDown"/>
<Button x:Name="ToMaxButton" Content="ToMaxButton" Click="ToMaxButton_Click" Height="30" Margin="5"/>
<Button x:Name="ToNormalButton" Content="ToNormalButton" Click="ToNormalButton_Click" Height="30" Margin="5"/>
<Button x:Name="CloseButton" Content="CloseButton" Click="CloseButton_Click" Height="30" Margin="5"/>
</DockPanel>
</Window>
和
namespace WpfApplication24
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void DragRectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void ToMaxButton_Click(object sender, RoutedEventArgs e)
{
this.WindowState = System.Windows.WindowState.Maximized;
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void ToNormalButton_Click(object sender, RoutedEventArgs e)
{
this.WindowState = System.Windows.WindowState.Normal;
}
}
}
编辑:
通过拖动原来的Window,我们会发现我们需要拖动一点距离然后改变window.state,那么窗口的位置就会和光标的坐标差不多了。