2022-12-23
1、添加资源字典文件style.xmal
2、在资源字典中添加自定义style等
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfTest.resources"> <Style x:Key="for_noresize_window" TargetType="{x:Type Window}"> <Setter Property="AllowsTransparency" Value="true"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="FontFamily" Value="Consolas, Microsoft YaHei"/> <Setter Property="ResizeMode" Value="NoResize"/> <Setter Property="WindowStyle" Value="None"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Window}"> <Grid Margin="10"> <Rectangle Fill="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" RadiusX="5" RadiusY="5"> <Rectangle.Effect> <DropShadowEffect BlurRadius="10" ShadowDepth="0"/> </Rectangle.Effect> </Rectangle> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Margin}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" CornerRadius="5"> <ContentPresenter /> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>
3、引用自定义文件:打开App.xaml文件,在<Application.Resources></Application.Resources>中添加资源字典文件引用
<style="color:rgb(98 189 255)">Application x:Class="style="color:rgb(253 97 106)">WpfTest.App"
xmlns="http://style="color:rgb(253 97 106)">schemas.style="color:rgb(98 189 255)">microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://style="color:rgb(253 97 106)">schemas.style="color:rgb(98 189 255)">microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:style="color:rgb(253 97 106)">WpfTest"
StartupUri="style="color:rgb(98 189 255)">MainWindow.xaml">
<style="color:rgb(98 189 255)">Application.Resources>
<style="color:rgb(98 189 255)">ResourceDictionary>
<style="color:rgb(98 189 255)">ResourceDictionary.MergedDictionaries>
<style="color:rgb(98 189 255)">ResourceDictionary Source="resources/style.xaml"/>
</style="color:rgb(98 189 255)">ResourceDictionary.MergedDictionaries>
</style="color:rgb(98 189 255)">ResourceDictionary>
</style="color:rgb(98 189 255)">Application.Resources>
</style="color:rgb(98 189 255)">Application>
4、将样式应用到窗口的布局上,边框阴影窗体
<Window x:Class="WpfTest.Window1" 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:WpfTest" mc:Ignorable="d" Title="Window1" Style="{StaticResource for_noresize_window}"> <Grid> </Grid> </Window>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2013-03-15 (转)iPhone wifi使用socket连接Internet