Wpf 简单制作自己的窗体样式


<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"
Title="MainWindow" AllowsTransparency="True" WindowStyle="None"
Width="640" Height="480">
<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="#FF0EED80"/>
</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>
</Grid.RowDefinitions>
<Border Background="#FF0DAD5F" MouseDown="Grid_MouseDown" CornerRadius="2,2,0,0">
<Grid Name="Title">
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center"> My window</TextBlock>
<Button Content="X" Foreground="White" HorizontalAlignment="Right" 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="56" Margin="130,127,209,0" Style="{DynamicResource myBtnStyle}" VerticalAlignment="Top"/>
</Grid>
</Grid>
</Border>
</Window>
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}
Wpf 简单制作自己的窗体样式的更多相关文章
- Wpf 简单制作自己的窗体样式(2)
上一篇blog讲了制作简单的样式的窗体,对于一个传统的窗体,不仅仅可以拖动,和关闭操作.还具有最大化.最小化.隐藏,以及改变窗体的大小等.这篇blog就是对上篇的补充,完善窗体的改变大小和最大化最小化 ...
- 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拖动相 ...
随机推荐
- android的个人代码总结
1.关于一个动作的实现,在Activity中可以用实现一个接口的方式来实现,在实现代码时可用IF进行判断是那个要执行的动作: 2.在软件开发过程中,软件界面的布局也非常重要:还是要多看看:
- 【报错】"The constructor Notification(int, CharSequence, long) is deprecated
Notification的构造方法 Notification(int, CharSequence, long) 在API11之后就淘汰了,之后的API需要用Notification.Builder() ...
- MAC下查看端口占用并杀死进程
Eclipse在Run on Server时,Tomcat是开启的,但是报错,显示8080.8005和8009端口被占用 终端输入 查看所有开启的端口 sudo lsof -i -P | grep - ...
- Composer PHP 依赖管理工具
composer 是 PHP 用来管理依赖(dependency)关系的工具.你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer 会帮你安装这些依赖的库文件. 依赖管理 ...
- [转]How to convert IP address to country name
本文转自:http://www.codeproject.com/Articles/28363/How-to-convert-IP-address-to-country-name Download ...
- 虚拟机 VirtualBox 自制帮助文档
初学 VirtualBox ,网络上教程很多,图片一张一张的费流量,讲得又比较散,于是花了一下午制作了此 CHM 帮助文档. 下载:(图片另存为--重命名为 RhinoC.rar --解压缩)
- ZooKeeper(3.4.5) - 开源客户端 Curator(2.7.0) 的简单示例
一.创建会话 1. 创建会话 package com.huey.dream.demo; import org.apache.curator.framework.CuratorFramework; im ...
- As,is含义?using 语句
Is:检查对象是否与给定的类型兼容.例如,下面的代码可以确定MyObject类型的一个实例,或者对象是否从MyObject派生的一个类型: if(obj is MyObject){} ...
- 程序生成SiteMapPath文件
//创建站点地图 private void CreateSiteMap(DataSet ds) { XmlDeclaration declareation; declareation = xmlDoc ...
- android手机操作SD的使用方法
写入SD卡 package com.example.openfileproject; import java.io.File; import java.io.FileInputStream; impo ...