少量代码设计一个登录界面(二) – .NET CORE(C#) WPF开发
阅读导航
- 本文背景
- 代码实现
- 本文参考
- 源码
1. 本文背景
同上篇文章《少量代码设计一个登录界面》,本篇介绍另一种登录界面设计风格。


2. 代码实现
使用 .NET CORE 3.1 创建名为 “Login” 的WPF模板项目,添加1个Nuget库:MaterialDesignThemes.3.1.0-ci981。
解决方案主要文件目录组织结构:
- Login
- App.xaml
- MainWindow.xaml
- MainWindow.xaml.cs
2.1 App.xaml文件引入样式
文件【App.xaml】,在 StartupUri 中设置启动的视图【MainWindow.xaml】,并在【Application.Resources】节点增加 MaterialDesignThemes库的样式文件:
<Application x:Class="Login.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
2.2 MainWindow.xaml 登录窗体
文件【MainWindow.xaml】,设计登录主界面,代码量很小,源码如下:
<Window x:Class="Login.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Login" Height="400" Width="600" ResizeMode="NoResize" WindowStyle="None"
AllowsTransparency="True" Background="Transparent" WindowStartupLocation="CenterScreen"
MouseLeftButtonDown="MoveWindow_MouseLeftButtonDown">
<Grid>
<Rectangle RadiusY="8" RadiusX="8" Fill="White"/>
<Rectangle Margin="310,0,0,0" RadiusX="8" RadiusY="8">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#CC935E12" Offset="1"/>
<GradientStop Color="#CCEA4646"/>
<GradientStop Color="#CCB89128" Offset="0.566"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<StackPanel Margin="20,10,290,10">
<Label Content="登录" FontFamily="Segoe UI Black" FontSize="24" Margin="0,10" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<StackPanel Orientation="Horizontal">
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" TextWrapping="Wrap" Foreground="#707070"><Run Text="你没有帐户吗?"/></TextBlock>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" TextWrapping="Wrap" Foreground="#FF2468AC"><Run Text="创建一个帐户,"/></TextBlock>
</StackPanel>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" TextWrapping="Wrap" Foreground="#707070"><Run Text="那不需要撒谎。"/></TextBlock>
<StackPanel Margin="0,15" Orientation="Horizontal">
<materialDesign:PackIcon Kind="Account" VerticalAlignment="Center" Foreground="#707070"/>
<TextBox materialDesign:HintAssist.Hint="账号" Width="250" Margin="5"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Key" VerticalAlignment="Center" Foreground="#707070"/>
<PasswordBox materialDesign:HintAssist.Hint="密码" Width="250" Margin="5"/>
</StackPanel>
<Grid>
<CheckBox Content="记住我" Margin="5,10" Foreground="#707070"/>
<Label Content="我忘了密码" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="10" Foreground="#707070"/>
</Grid>
<Button HorizontalAlignment="Center" Content="登录" FontFamily="Impact" FontSize="18" Width="100" Background="#FF307CD6" BorderBrush="#FF307CD6"/>
<StackPanel Orientation="Horizontal" Margin="10,35">
<Label Content="第三方登录" Foreground="#707070" VerticalAlignment="Center"/>
<Button HorizontalAlignment="Center" FontFamily="Impact" FontSize="18" Background="#FF3D56AC" BorderBrush="#FF3D56AC">
<materialDesign:PackIcon Kind="Wechat" VerticalAlignment="Center" Foreground="White"/>
</Button>
<Button HorizontalAlignment="Center" FontFamily="Impact" FontSize="18" Margin="15,0" Background="#FF01BAFF" BorderBrush="#FF01BAFF">
<materialDesign:PackIcon Kind="Qqchat" VerticalAlignment="Center" Foreground="White"/>
</Button>
<Button HorizontalAlignment="Center" FontFamily="Impact" FontSize="18" Background="#FFE05959" BorderBrush="#FFE05959">
<materialDesign:PackIcon Kind="SinaWeibo" VerticalAlignment="Center" Foreground="White"/>
</Button>
</StackPanel>
</StackPanel>
<Button BorderBrush="{x:Null}" Background="{x:Null}" HorizontalAlignment="Right" VerticalAlignment="Top"
Click="CloseWindow_Click">
<materialDesign:PackIcon Kind="Close"/>
</Button>
<StackPanel Margin="310,50,0,50">
<TextBlock Text="欢迎回来" Foreground="White" HorizontalAlignment="Center" FontSize="48" FontFamily="Champagne & Limousines" FontWeight="Bold"/>
<TextBlock Text="使不可能成为可能,使可能变得简单而优雅" Foreground="White" HorizontalAlignment="Center" Width="280" FontSize="24" FontFamily="Champagne & Limousines" TextWrapping="Wrap" TextAlignment="Center" Margin="0,50,0,0"/>
<TextBlock Text="https://dotnet9.com" Foreground="White" FontSize="18" FontFamily="Champagne & Limousines" TextWrapping="Wrap" TextAlignment="Right" Margin="10"/>
</StackPanel>
</Grid>
</Window>
下面是后台代码:文件【MainWindow.xaml.cs】,关闭窗体、窗体移动等事件处理。
using System.Windows;
using System.Windows.Input;
namespace Login
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void CloseWindow_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void MoveWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
}
}
3.本文参考
4.源码
演示代码已全部奉上,为了方便演示,代码中的图片使用本站外链,代码可直接拷贝并按代码结构组织编译即可运行。
除非注明,文章均由 Dotnet9 整理发布,欢迎转载。
转载请注明本文地址:https://dotnet9.com/8091.html
欢迎扫描下方二维码关注 Dotnet9 的微信公众号,本站会及时推送最新技术文章
时间如流水,只能流去不流回!
点击《【阅读原文】》,【Dotnet9的博客】站点还有更多技术类文章等着您哦!!!
此刻顺便为我点个《【再看】》可好?
少量代码设计一个登录界面(二) – .NET CORE(C#) WPF开发的更多相关文章
- 少量代码设计一个登录界面 - .NET CORE(C#) WPF开发
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. 少量代码设计一个登录界面 - .NET CORE(C#) WPF开发 阅读导航 本文背景 代码 ...
- winform设计一个登录界面和修改密码的界面-自动切换窗体(问题[已解] 望一起讨论)(技术改变世界-cnblog)
http://www.cnblogs.com/IAmBetter/archive/2012/01/14/2322156.html winform设计一个登录界面和修改密码的界面-自动切换窗体(问题[已 ...
- 二、Django用Eclipse编写一个登录界面
一.Django用Eclipse编写一个登录界面 二.Django用Eclipse编写一个登录界面Ajax和Django交互 各软件版本:Python 2.7.14,django 1.6.11 原来已 ...
- 使用Axure RP原型设计实践03,制作一个登录界面的原型
本篇体验做一个登录界面的原型. 登录页 首先在Page Style里为页面设置背景色. 如果想在页面中加图片,就把Image部件拖入页面,并设置x和y轴.双击页面中的Image部件可以导入图片.在Im ...
- 一、Django用Eclipse编写一个登录界面
一.Django用Eclipse编写一个登录界面 二.Django用Eclipse编写一个登录界面Ajax和Django交互 Eclipse安装Python插件和Django的步骤直接省略. 创建de ...
- gtk---实现一个登录界面
输入框 如果在GTK+中需要输入一个字符串,可以使用输入框,这是一个单行的输入构件,可以用于输入和显示正文内容. 输入框的基本操作函数 1.gtk_entry_new(void); 这是新建一个输入框 ...
- 简易音乐播放器主界面设计 - .NET CORE(C#) WPF开发
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. 简易音乐播放器主界面设计 - .NET CORE(C#) WPF开发 阅读导航 本文背景 代码 ...
- tkinter+pickle+python的一个登录界面设计
1.代码: #导出模块 import tkinter as tk from tkinter import messagebox import pickle #定义登录的窗口.标题.大小和位置 wind ...
- 浅谈DevExpress<二>:设计一个完整界面(1)
昨天谈了界面的换肤问题,今天拿一个简单的界面来介绍一下怎么设计一个五脏俱全的界面,总体效果如下图(种类的图片随便找的^^):
随机推荐
- Java单体应用 - 架构模式 - 01.三层架构
原文地址:http://www.work100.net/training/monolithic-architecture-3level.html 更多教程:光束云 - 免费课程 三层架构 序号 文内章 ...
- elasticjob学习一:simplejob初识和springboot整合
Elastic-Job是一个分布式调度解决方案,由两个相互独立的子项目Elastic-Job-Lite和Elastic-Job-Cloud组成. Elastic-Job-Lite定位为轻量级无中心化解 ...
- SpringMvc简单使用
SpringMvc框架的简单使用 第一步:导入依赖 <dependencies> <dependency> <groupId>org.springframework ...
- 部署Maven项目到tomcat报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderLi
Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL 严重: Error config ...
- 个人第4次作业—Alpha项目测试
这个作业属于哪个课程 课程链接 这个作业要求在哪里 作业要求 团队名称 CTRL_IKUN(团队博客) 这个作业的目标 对非本小组的三个项目进行软件测试 一.测试人员个人信息 学号 201731032 ...
- Bate冲刺博客(3次)
Bate冲刺博客 课程介绍 课程 (https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience) 作业要求 https://www ...
- php--->自己封装的简易版mvc框架
最近根据自己的理解,封装了一个自己的框架,来重新系统化梳理自己对mvc框架的理解:后续会陆续添加各种新的功能. 欢迎指点交流. GitHub:https://github.com/Frankltf/m ...
- 双括号(()),shell与C++的桥梁
使用语法: ((表达式))用来扩展Shell中的算术运算,以及赋值运算,扩展for,while,if条件测试运算. 注意点: 1.在双括号结构中,所有的表达式可以像c语言一样,如a++,b-- 2.在 ...
- pandas使用的25个技巧
本文翻译自https://nbviewer.jupyter.org/github/justmarkham/pandas-videos/blob/master/top_25_pandas_trick ...
- HDU_2084_DP
http://acm.hdu.edu.cn/showproblem.php?pid=2084 简单dp,从下到上,从左到右,依次更新每个位置最大值. #include<iostream> ...
