先看效果:
自定义WindowChrome
通过WindowChrome
的ResizeBorderThickness
属性进行设置
XAML代码
<Window x:Class="SmartClient.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SmartClient"
xmlns:extendedResizeBorder="clr-namespace:ExtendedResizeBorder;assembly=ExtendedResizeBorder"
mc:Ignorable="d"
Style="{StaticResource NoResize_window}"
Title="MainWindow" Height="780" Width="1200" Loaded="Window_Loaded">
<extendedResizeBorder:ExtendedResizeBorder.ExtendedResizeBorder>
<extendedResizeBorder:ExtendedResizeBorder Radius="8" />
</extendedResizeBorder:ExtendedResizeBorder.ExtendedResizeBorder>
<WindowChrome.WindowChrome>
<WindowChrome ResizeBorderThickness="10"></WindowChrome>
</WindowChrome.WindowChrome>
<Grid Background="Transparent" MouseDown="UIElement_OnMouseDown" x:Name="wb">
<!--<Grid Background="White" />-->
<!--<Button Width="100" Height="100" Command="Undo" />-->
</Grid>
</Window>
后台代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
// 获取鼠标相对标题栏位置
Point position = e.GetPosition(wb);
// 如果鼠标位置在标题栏内,允许拖动
if (e.LeftButton == MouseButtonState.Pressed)
{
if (position.X >= 0 && position.X < wb.ActualWidth && position.Y >= 0 && position.Y < wb.ActualHeight)
{
this.DragMove();
}
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
{
}
}