Wpf 简单制作自己的窗体样式(2)
上一篇blog讲了制作简单的样式的窗体,对于一个传统的窗体,不仅仅可以拖动,和关闭操作、还具有最大化、最小化、隐藏,以及改变窗体的大小等。这篇blog就是对上篇的补充,完善窗体的改变大小和最大化最小化的功能。
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="WpfAppBlog.MainWindow" x:Name="Window" Background="Transparent" MinWidth="640" MinHeight="480" Title="MainWindow" AllowsTransparency="True" WindowStyle="None" > <Window.Resources> <Style x:Key="myBtnStyle" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition x:Name="columnDefinition1" Width="0.982*"/> <ColumnDefinition x:Name="columnDefinition" Width="0.018*"/> </Grid.ColumnDefinitions> <Rectangle x:Name="rectangle" RadiusY="2" RadiusX="2" Stroke="{x:Null}" Fill="#FF0DAD5F" Grid.ColumnSpan="2"/> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsFocused" Value="True"> <Setter Property="Stroke" TargetName="rectangle" Value="{x:Null}"/> <Setter Property="Fill" TargetName="rectangle" Value="#FF0DAD5F"/> </Trigger> <Trigger Property="IsDefaulted" Value="True"> <Setter Property="Fill" TargetName="rectangle" Value="#FF0DAD5F"/> <Setter Property="Stroke" TargetName="rectangle" Value="{x:Null}"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Stroke" TargetName="rectangle" Value="{x:Null}"/> <Setter Property="Fill" TargetName="rectangle" Value="#FF83D245"/> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter Property="Stroke" TargetName="rectangle" Value="{x:Null}"/> <Setter Property="Fill" TargetName="rectangle" Value="#FF17D256"/> <Setter Property="Width" TargetName="columnDefinition" Value="Auto"/> <Setter Property="MinWidth" TargetName="columnDefinition" Value="0"/> <Setter Property="Width" TargetName="columnDefinition1" Value="*"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Stroke" TargetName="rectangle" Value="{x:Null}"/> <Setter Property="Fill" TargetName="rectangle" Value="{x:Null}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Border BorderBrush="#FF0DAD5F" BorderThickness="3" CornerRadius="4"> <Grid > <Grid.RowDefinitions> <RowDefinition Height="30"></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition Height="5"></RowDefinition> </Grid.RowDefinitions> <Border Background="#FF0DAD5F" BorderBrush="Transparent" MouseDown="Grid_MouseDown" CornerRadius="2,2,0,0"> <Grid Name="Title" Margin="0"> <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center"> My window</TextBlock> <Button Content="一" Name="btnMin" Click="btnMin_Click" HorizontalAlignment="Right" Foreground="White" Margin="0,0,45,0" Height="20" Width="20" Style="{DynamicResource myBtnStyle}" VerticalAlignment="Center" /> <Button Content="口" Name="btnMaxOrMin" Click="btnMaxOrMin_Click" HorizontalAlignment="Right" Foreground="White" Margin="0,0,25,0" Height="20" Width="20" Style="{DynamicResource myBtnStyle}" VerticalAlignment="Center" /> <Button Content="X" HorizontalAlignment="Right" Foreground="White" Margin="0,0,5,0" Height="20" Width="20" Style="{DynamicResource myBtnStyle}" VerticalAlignment="Center" Click="Button_Click" /> </Grid> </Border> <Grid Grid.Row="1" Background="White" > <Button Content="Button" Height="36" Width="120" Margin="130,127,209,0" Style="{DynamicResource myBtnStyle}" VerticalAlignment="Top"/> </Grid> <Grid Grid.Row="2" Background="White"> <Border Height="5" Width="5" Background="White" CornerRadius="500,0,0,0" VerticalAlignment="Bottom" HorizontalAlignment="Right" Cursor="SizeNWSE" MouseLeftButtonDown="Border_MouseLeftButtonDown" MouseLeftButtonUp="Border_MouseLeftButtonUp" MouseMove="Border_MouseMove"> </Border> </Grid> </Grid> </Border> </Window>
后台:
/// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); // 在此点下面插入创建对象所需的代码。 } private void Button_Click(object sender, RoutedEventArgs e) { this.Close(); } private void Grid_MouseDown(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DragMove(); } } //拖动改变窗体大小 bool isWiden = false; Rect rcnormal;//定义一个全局rect记录还原状态下窗口的位置和大小。 private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { isWiden = true; } private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { isWiden = false; Border b = (Border)sender; b.ReleaseMouseCapture(); } private void Border_MouseMove(object sender, MouseEventArgs e) { Border b = (Border)sender; if (isWiden) { b.CaptureMouse(); ; ; ) { this.Width = newWidth; } ) { this.Height = newheight; } } } private void btnMin_Click(object sender, RoutedEventArgs e) { this.WindowState = WindowState.Minimized; } private void btnMaxOrMin_Click(object sender, RoutedEventArgs e) { Rect rc = SystemParameters.WorkArea;//获取工作区大小 if (this.Width == rc.Width) { this.Left = rcnormal.Left; this.Top = rcnormal.Top; this.Width = rcnormal.Width; this.Height = rcnormal.Height; } else { rcnormal = new Rect(this.Left, this.Top, this.Width, this.Height);//保存下当前位置与大小 ;//设置位置 ; this.Width = rc.Width; this.Height = rc.Height; } } }

Wpf 简单制作自己的窗体样式(2)的更多相关文章
- Wpf 简单制作自己的窗体样式
最近一直在搞wpf相关的东东,由于还在门外徘徊,所以第一篇blog写了简单的制作扁平化的wpf button样式,这一篇也简单的制作属于自己wpf 窗体的样式. 废话少说,下面就开始制作自己的窗体样式 ...
- WPF中制作无边框窗体
原文:WPF中制作无边框窗体 众所周知,在WinForm中,如果要制作一个无边框窗体,可以将窗体的FormBorderStyle属性设置为None来完成.如果要制作成异形窗体,则需要使用图片或者使用G ...
- 01.WPF中制作无边框窗体
[引用:]http://blog.csdn.net/johnsuna/article/details/1893319 众所周知,在WinForm中,如果要制作一个无边框窗体,可以将窗体的FormB ...
- wpf 导出Excel Wpf Button 样式 wpf简单进度条 List泛型集合对象排序 C#集合
wpf 导出Excel 1 private void Button_Click_1(object sender, RoutedEventArgs e) 2 { 3 4 ExportDataGrid ...
- WPF自定义Window窗体样式
资源文件代码: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation ...
- WPF简单入门总结
WPF简单总结 最近看了点关于WPF的东西,总结了点点入门的东西. XAML语法基础 1. 定义样式 <Window.Resources><!--窗体资源的定义--> < ...
- .NET CORE(C#) WPF简单菜单MVVM绑定
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. .NET CORE(C#) WPF简单菜单MVVM绑定 阅读导航 本文背景 代码实现 本文参考 ...
- Winform自定义窗体样式,实现标题栏可灵活自定义
最近在编写C/S结构应用程序时,感觉窗体的标题栏样式太死板了,标题文字不能更改大小.颜色.字体等,按钮不能隐藏等问题,在网上也查找了许多相关的资料,没有找到合适的解决方案,发现许多人也在寻求这个问题, ...
- WPF流程图制作系列相关基础一
WPF流程图制作相关基础一 需求是要通过wpf开发流程图,这个流程图是用户自行拖动配置. 使用过流程图的话,应该大体能想象出流程图拖动配置的样子.这里主要会涉及到的技术知识点就是 wpf拖动相 ...
随机推荐
- ORACLE 导入导出操作
1.导入命令: imp userId/psw@orcl full=y file=D:\data\xxx.dmp ignore=y 2.导出命令 exp userId/psw@orcl file=d: ...
- SQL Server :事务和锁
1.事务 事务概念:全部执行或全部不执行的一条或者多条语句的组合 例子说明:到银行里转账,将一个账户(Tom)里的100元钱转到另一个账户(Jake) update table money=money ...
- LeetCode 226
Invert Binary Tree Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 /** ...
- 【基础数学知识】UVa 11314 - Hardly Hard
Problem H HARDLY HARD You have been given the task of cutting out a quadrilateral slice of cake out ...
- hdu 3440 差分约束
看完题目第一遍,感觉很简单.当写完程序跑测试用例的时候,发现第二个总是过不了,然后好好研究了一下测试用例,才知道原来不是程序有问题,而是我的建图方式错了.对于这些无序的点,如果高的在右边,不等式是di ...
- poj 2195 二分图最优匹配 或 最小费用最大流
就是最基本的二分图最优匹配,将每个人向每个房子建一条边,权值就是他们manhattan距离.然后对所有权值取反,求一次最大二分图最优匹配,在将结果取反就行了. #include<iostream ...
- MyEclipse8.5集成Tomcat7时的启动错误:Exception in thread “main” java.lang.NoClassDefFoundError org/apache/commons/logging/LogFactory
今天,安装Tomcat7.0.21后,单独用D:\apache-tomcat-7.0.21\bin\startup.bat启动web服务正常.但 在MyEclipse8.5中集成配置Tomcat7后, ...
- MyBatis(3.2.3) - Handling enumeration types
MyBatis supports persisting enum type properties out of the box. Assume that the STUDENTS table has ...
- HDOJ2025查找最大元素
查找最大元素 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- UML——类和对象