[Citation:]http://blog.csdn.net/johnsuna/article/details/1893319
As we all know, in WinForm, if you want to make a borderless form, you can set the FormBorderStyle property of the form to none to complete.
If you want to make an alien form, you need to use a picture or custom draw with GDI +.
So, in WPF, how do we make a borderless form?
The answer is to set the window's WindowStyle property to None, which is windowstyle= "none". If the non-rectangular shaped form, you need to set the background to Null, will allow transparent set to true, that is: background= "{x:null}" allowstransparency= "True", some people may also want this window can be dragged to drag, then , you also need to set the MouseLeftButtonDown event, such as: mouseleftbuttondown= "Dragwindow", here Dragwindow by the window DragMove () to complete. Want to close the window? Then make a button yourself and then use the close () method of the window itself.
Here are the effects:
There's a circular X button in the upper right corner, which is made with a button, but it's styled as a rounded rectangle. See below for specific code:
XAML Code:
Window1.xaml
<window x:class= "Borderlesswindow.window1"
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
Title= "Borderlesswindow" height= "width=" 300 "
windowstyle= "None" background= "{x:null}" allowstransparency= "True"
Mouseleftbuttondown= "Dragwindow"
>
<Window.Resources>
<style x:key= "ButtonStyle" targettype= "{x:type button}" >
<setter property= "Foreground" value= "white"/>
<setter property= "Template" >
<Setter.Value>
<!--setting Styles--
<controltemplate targettype= "{x:type button}" >
<Grid>
<rectangle x:name= "Rectangle" stroke= "#FFFFFFFF" strokemiterlimit= "1.000000" strokethickness= "0.500000" Radiusx= "Ten" radiusy= "fill=" #FF777777 ">
</Rectangle>
<contentpresenter x:name= "ContentPresenter" snapstodevicepixels= "{TemplateBinding snapstodevicepixels}" Horizontalalignment= "{TemplateBinding horizontalcontentalignment}"
Verticalalignment= "{TemplateBinding verticalcontentalignment}" recognizesaccesskey= "True"/>
</Grid>
<!--set the mouse to the effect on the Close button--
<ControlTemplate.Triggers>
<trigger property= "IsMouseOver" value= "true" >
<setter property= "Fill" targetname= "Rectangle" >
<Setter.Value>
<solidcolorbrush color= "White" ></SolidColorBrush>
</Setter.Value>
</Setter>
<setter property= "Foreground" value= "Black" ></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<!--content in a form--
<Grid>
<!--
The border of the form, the background setting, note that the Cornerradius is consistent with the setting of the "X" fork button in the upper-left corner or about greater than the fork buttonradiusx/ySettings-
<border cornerradius= "10,10,10,10" background= "Orange" height= "Auto" borderbrush= "Teal" borderthickness= "1" > </Border>
<!--the "X" fork button in the upper-left corner--
<button name= "Button1" style= "{StaticResource buttonstyle}" click= "CloseWindow" width= "All" height= "all content=" X " Horizontalalignment= "Right" verticalalignment= "Top" margin= "3,3,3,3" ></Button>
<button height= "margin=" 96,101,121,0 "name=" Button2 "verticalalignment=" Top ">test button</button>
</Grid>
</Window>
C # code:
Window1.xaml.cs
Using System;
Using System.Collections.Generic;
Using System.Text;
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.Shapes;
Namespace Borderlesswindow
{
<summary>
Interaction Logic for Window1.xaml
</summary>
public partial class Window1:System.Windows.Window
{
Public Window1 ()
{
InitializeComponent ();
}
public void Dragwindow(object sender, MouseButtonEventArgs args)
{
This . DragMove ();
}
public void CloseWindow(object sender, RoutedEventArgs args)
{
This . Close ();
}
}
}
Create a borderless form in 01.WPF