WPF设置窗口模式(Windowstyle=“None”)

当WindowStyle=“None”时,设置AllowsTransparency="True",则不会出现黑色Border,然后可以另外设置外边的Border和BorderThickness;

当WindowStyle=“None”时,生成的窗体无法移动,此时需要定义MouseMove="Window_MouseMove"事件,实现鼠标左键按下可拖动窗口;

xaml代码如下:

<Window x:Class="CustomWindowDemo.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:CustomWindowDemo"
mc:Ignorable="d" MouseMove="Window_MouseMove"
WindowStyle="None" AllowsTransparency="True" BorderBrush="Orange" BorderThickness="3,0,3,3"
Title="MainWindow" Height="" Width="">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height=""></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height=""></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="" Background="Orange">
<TextBlock Margin="20,5,5,5" Foreground="Red" Text="TestWindow" FontSize="" VerticalAlignment="Center"/>
</StackPanel>
<TextBlock Margin="20,30" FontSize="" Text="This is a Test Window of customized." Grid.Row="" TextAlignment="Center" VerticalAlignment="Center"></TextBlock>
<StackPanel Grid.Row="" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Name="Cancel" Click="Cancel_Click" Margin="0,5,20,5" Height="" Width="">Cancel</Button>
<Button Name="Confirm" Click="Confirm_Click" Margin="20,5,0,5" Height="" Width="">Confirm</Button>
</StackPanel>
</Grid>
</Window>

后台代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace CustomWindowDemo
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void Confirm_Click(object sender, RoutedEventArgs e)
{
this.Close();
} private void Cancel_Click(object sender, RoutedEventArgs e)
{
this.Close();
} private void Window_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
//Window.DragMove();
}
}
}
}
上一篇:hdu 4649 Professor Tian 反状态压缩+概率DP


下一篇:Delphi 调用系统中的计算器、记事本、画图软件方法