【.Net码农】WPF界面—仿360安全卫士9.0界面

2023-10-21 06:50

本文主要是介绍【.Net码农】WPF界面—仿360安全卫士9.0界面,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

http://blog.csdn.net/ljf5566/article/details/8758922


主要思路如下:

该界面主要有三大部分

第一部分:标题栏部分就是最上面那一行

第二部分:内容区域(也就是页标签部分)

第三部分:换肤部分(点击换肤小按钮弹出的内容部分)

根据分析我们可以使用一个有两行的网格(Grid)进行布局,第一行“标题栏”部分;第二行“页标签部分”,对于“换肤部分”是直接显示在当前界面之上的内容,使用"Popup"标签实现。

代码很长,我只粘贴部分代码,随后将上传至资源区


1、定义无边框窗体样式和Button样式

  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  2.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">  
  3.     <!--无边框的窗体样式-->  
  4.     <Style x:Key="NoResize_window" TargetType="{x:Type Window}">  
  5.         <Setter Property="AllowsTransparency" Value="true"/>  
  6.         <Setter Property="Background" Value="Transparent"/>  
  7.         <!-- <Setter Property="ResizeMode" Value="CanResizeWithGrip"/>-->  
  8.         <Setter Property="WindowStyle" Value="None"/>  
  9.         <Setter Property="Template">  
  10.             <Setter.Value>  
  11.                 <ControlTemplate TargetType="{x:Type Window}">  
  12.                     <Grid Margin="5">  
  13.                         <Rectangle Fill="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"    >  
  14.                             <Rectangle.Effect>  
  15.                                 <DropShadowEffect BlurRadius="5" ShadowDepth="0"/>  
  16.                             </Rectangle.Effect>  
  17.                         </Rectangle>  
  18.                         <Border Background="{TemplateBinding Background}"      
  19.                         BorderBrush="{TemplateBinding BorderBrush}"      
  20.                         BorderThickness="{TemplateBinding BorderThickness}"      
  21.                         Padding="{TemplateBinding Margin}"      
  22.                         SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">  
  23.                             <ContentPresenter />  
  24.                         </Border>  
  25.                     </Grid>  
  26.                 </ControlTemplate>  
  27.             </Setter.Value>  
  28.         </Setter>  
  29.     </Style>  
  30.     <!--Button样式-->  
  31.     <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">  
  32.         <Setter Property="Template">  
  33.             <Setter.Value>  
  34.                 <ControlTemplate TargetType="{x:Type Button}">  
  35.                     <Grid>  
  36.                         <VisualStateManager.VisualStateGroups>  
  37.                             <VisualStateGroup x:Name="CommonStates">  
  38.                                 <VisualState x:Name="MouseOver"/>  
  39.                                 <VisualState x:Name="Pressed"/>  
  40.                                 <VisualState x:Name="Disabled"/>  
  41.                             </VisualStateGroup>  
  42.                             <VisualStateGroup x:Name="FocusStates">  
  43.                                 <VisualState x:Name="Focused"/>  
  44.                             </VisualStateGroup>  
  45.                             <VisualStateGroup x:Name="ValidationStates">  
  46.                                 <VisualState x:Name="InvalidFocused"/>  
  47.                                 <VisualState x:Name="InvalidUnfocused"/>  
  48.                             </VisualStateGroup>  
  49.                         </VisualStateManager.VisualStateGroups>  
  50.                         <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Margin="5">  
  51.                             <Border.Effect>  
  52.                                 <DropShadowEffect ShadowDepth="0" Opacity="0.85"/>  
  53.                             </Border.Effect>  
  54.                         </Border>  
  55.                         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}"/>  
  56.                     </Grid>  
  57.                     <ControlTemplate.Triggers>  
  58.                         <Trigger Property="IsFocused" Value="True"/>  
  59.                         <Trigger Property="IsDefaulted" Value="True"/>  
  60.                         <Trigger Property="IsMouseOver" Value="True">  
  61.                             <Setter Property="Effect" TargetName="border">  
  62.                                 <Setter.Value>  
  63.                                     <DropShadowEffect Color="#FF00F3FF" Opacity="0.85" ShadowDepth="0"/>  
  64.                                 </Setter.Value>  
  65.                             </Setter>  
  66.                         </Trigger>  
  67.                         <Trigger Property="IsPressed" Value="True"/>  
  68.                         <Trigger Property="IsEnabled" Value="False"/>  
  69.                     </ControlTemplate.Triggers>  
  70.                 </ControlTemplate>  
  71.             </Setter.Value>  
  72.         </Setter>  
  73.     </Style>  
  74.     <!-- Resource dictionary entries should be defined here. -->  
  75. </ResourceDictionary>  


2、逻辑处理代码

  1. using System;  
  2. using System.Windows;  
  3. using System.Windows.Controls;  
  4. using System.Windows.Media;  
  5. using System.Xml;  
  6.   
  7. namespace _360UI9  
  8. {  
  9.     /// <summary>  
  10.     /// MainWindow.xaml 的交互逻辑  
  11.     /// </summary>  
  12.     public partial class MainWindow : Window  
  13.     {  
  14.         public MainWindow()  
  15.         {  
  16.             InitializeComponent();  
  17.             this.Loaded += MainWindow_Loaded;  
  18.         }  
  19.   
  20.         void MainWindow_Loaded(object sender, RoutedEventArgs e)  
  21.         {  
  22.             //窗体加载的时候获取保存的皮肤  
  23.             XmlDocument doc = new XmlDocument();  
  24.             string xmlpath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "skin.xml";  
  25.             doc.Load(xmlpath);  
  26.             XmlNode xnode = doc.SelectSingleNode("bd");  
  27.             XmlElement xe = (XmlElement)xnode["skin"];  
  28.             skinbrush.Background = App.Current.FindResource(xe.GetAttribute("name")) as Brush;  
  29.         }  
  30.         //换肤  
  31.         private void btnChangeSkin_Click(object sender, RoutedEventArgs e)  
  32.         {  
  33.             //显示换肤界面  
  34.             skinui.IsOpen = true;  
  35.         }  
  36.         //反馈  
  37.         private void btnFeedback_Click(object sender, RoutedEventArgs e)  
  38.         {  
  39.   
  40.         }  
  41.         //最小化  
  42.         private void btnMin_Click(object sender, RoutedEventArgs e)  
  43.         {  
  44.             this.WindowState = System.Windows.WindowState.Minimized;  
  45.         }  
  46.         //主菜单  
  47.         private void btnMainMenu_Click(object sender, RoutedEventArgs e)  
  48.         {  
  49.   
  50.         }  
  51.         //最大化  
  52.         private void btnMax_Click(object sender, RoutedEventArgs e)  
  53.         {  
  54.             if (this.WindowState != System.Windows.WindowState.Maximized)  
  55.             {  
  56.                 this.WindowState = System.Windows.WindowState.Maximized;  
  57.             }  
  58.             else  
  59.             {  
  60.                 this.WindowState = System.Windows.WindowState.Normal;  
  61.             }  
  62.         }  
  63.         //关闭  
  64.         private void btnClose_Click(object sender, RoutedEventArgs e)  
  65.         {  
  66.             this.Close();  
  67.         }  
  68.         //实现换肤  
  69.         private void ChangeSkin(object sender, RoutedEventArgs e)  
  70.         {  
  71.             Button bt = (Button)sender;  
  72.             skinbrush.Background = App.Current.FindResource(bt.Name) as Brush;  
  73.             //将选择的皮肤保存到XML文件  
  74.             XmlDocument doc = new XmlDocument();  
  75.             string xmlpath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "skin.xml";  
  76.             doc.Load(xmlpath);  
  77.             XmlNode xnode = doc.SelectSingleNode("bd");  
  78.             XmlElement xe = (XmlElement)xnode["skin"];  
  79.             xe.SetAttribute("name", bt.Name);  
  80.             doc.Save(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "skin.xml");  
  81.         }  
  82.     }  
  83. }  

效果如下:



源代码下载:点击打开链接


这篇关于【.Net码农】WPF界面—仿360安全卫士9.0界面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/252673

相关文章

解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题

《解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题》:本文主要介绍解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4... 目录未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘打开pom.XM

CSS3打造的现代交互式登录界面详细实现过程

《CSS3打造的现代交互式登录界面详细实现过程》本文介绍CSS3和jQuery在登录界面设计中的应用,涵盖动画、选择器、自定义字体及盒模型技术,提升界面美观与交互性,同时优化性能和可访问性,感兴趣的朋... 目录1. css3用户登录界面设计概述1.1 用户界面设计的重要性1.2 CSS3的新特性与优势1.

javax.net.ssl.SSLHandshakeException:异常原因及解决方案

《javax.net.ssl.SSLHandshakeException:异常原因及解决方案》javax.net.ssl.SSLHandshakeException是一个SSL握手异常,通常在建立SS... 目录报错原因在程序中绕过服务器的安全验证注意点最后多说一句报错原因一般出现这种问题是因为目标服务器

VS配置好Qt环境之后但无法打开ui界面的问题解决

《VS配置好Qt环境之后但无法打开ui界面的问题解决》本文主要介绍了VS配置好Qt环境之后但无法打开ui界面的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目UKeLvb录找到Qt安装目录中designer.UKeLvBexe的路径找到vs中的解决方案资源

使用WPF实现窗口抖动动画效果

《使用WPF实现窗口抖动动画效果》在用户界面设计中,适当的动画反馈可以提升用户体验,尤其是在错误提示、操作失败等场景下,窗口抖动作为一种常见且直观的视觉反馈方式,常用于提醒用户注意当前状态,本文将详细... 目录前言实现思路概述核心代码实现1、 获取目标窗口2、初始化基础位置值3、创建抖动动画4、动画完成后

使用easy connect之后,maven无法使用,原来需要配置-Djava.net.preferIPv4Stack=true问题

《使用easyconnect之后,maven无法使用,原来需要配置-Djava.net.preferIPv4Stack=true问题》:本文主要介绍使用easyconnect之后,maven无法... 目录使用easGWowCy connect之后,maven无法使用,原来需要配置-DJava.net.pr

在.NET平台使用C#为PDF添加各种类型的表单域的方法

《在.NET平台使用C#为PDF添加各种类型的表单域的方法》在日常办公系统开发中,涉及PDF处理相关的开发时,生成可填写的PDF表单是一种常见需求,与静态PDF不同,带有**表单域的文档支持用户直接在... 目录引言使用 PdfTextBoxField 添加文本输入域使用 PdfComboBoxField

使用DrissionPage控制360浏览器的完美解决方案

《使用DrissionPage控制360浏览器的完美解决方案》在网页自动化领域,经常遇到需要保持登录状态、保留Cookie等场景,今天要分享的方案可以完美解决这个问题:使用DrissionPage直接... 目录完整代码引言为什么要使用已有用户数据?核心代码实现1. 导入必要模块2. 关键配置(重点!)3.

基于.NET编写工具类解决JSON乱码问题

《基于.NET编写工具类解决JSON乱码问题》在开发过程中,我们经常会遇到JSON数据处理的问题,尤其是在数据传输和解析过程中,很容易出现编码错误导致的乱码问题,下面我们就来编写一个.NET工具类来解... 目录问题背景核心原理工具类实现使用示例总结在开发过程中,我们经常会遇到jsON数据处理的问题,尤其是

Node.js net模块的使用示例

《Node.jsnet模块的使用示例》本文主要介绍了Node.jsnet模块的使用示例,net模块支持TCP通信,处理TCP连接和数据传输,具有一定的参考价值,感兴趣的可以了解一下... 目录简介引入 net 模块核心概念TCP (传输控制协议)Socket服务器TCP 服务器创建基本服务器服务器配置选项服