Beginner WPF, using VS2012 to write a drag, resizable, custom button style of the borderless program.
The effect is as follows:
Implementation process:
First, drag, adjust the size, no border main reference: http://blog.csdn.net/dlangu0393/article/details/12548731
Two, the main completion of their own custom button effect.
1. WPF defines button style methods
(1) Add a resource dictionary file, such as Style.xaml. For example:
<ResourceDictionaryxmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"> <BitmapImagex:key= "Bgmin">/images/bg_min.png</BitmapImage> <BitmapImagex:key= "Bgminover">/images/bg_min_over.png</BitmapImage> <Stylex:key= "Btntemplate"TargetType= "button"> <Setter Property= "Template"> <Setter.value> <ControlTemplateTargetType="{x:type Button}"> <BorderBackground="{TemplateBinding Background}"> <ContentPresenterHorizontalAlignment= "Center"VerticalAlignment= "Center"/> </Border> </ControlTemplate> </Setter.value> </Setter> </Style> <Stylex:key= "Btnminstyle"TargetType= "button"BasedOn="{StaticResource Btntemplate}"> <Setter Property= "Background"> <Setter.value> <ImageBrushImageSource="{StaticResource Bgmin}"Stretch= "Fill"/> </Setter.value> </Setter> <style.triggers> <Trigger Property= "IsMouseOver"Value= "true"> <Setter Property= "Background"> <Setter.value> <ImageBrushImageSource="{StaticResource Bgminover}"Stretch= "Fill"/> </Setter.value> </Setter> </Trigger> </style.triggers> </Style></ResourceDictionary>
(2) Application style
Referencing a resource file in a form XAML file Style.xaml
<window.resources> <ResourceDictionary> <resourcedictionary.mergeddictionaries> <ResourceDictionarySource= "/theme/style.xaml"/> </resourcedictionary.mergeddictionaries> </ResourceDictionary></window.resources>
Set Button Style Property
<Style= "{StaticResource Btnminstyle}"/>
(3) If you want to set the style of the button in the form class, use the following method
this. Minimizebutton.style = (Style) resources["btnminstyle"];
2. The position of the button changes with the window size
Define rows and columns in a grid in form XAML, for example, set grid to two column
<Grid> ... <grid.columndefinitions> <ColumnDefinition/> <ColumnDefinitionWidth= " the"/> </grid.columndefinitions> ... ...</Grid>
The grid containing the buttons as child elements of the grid above, set in the second column
<x:name= "Systemcmdbar"Width= " grid.column"= "1">... </ Grid >
The Systemcmdbar contains three buttons. This way, if the width of the first column is not set, the Systemcmdbar in the second column will always be on the right side of the window.
Third, the source program: Ase0701.zip
[01] Borderless WPF program with drag, adjustable size, custom button style