少量代码设计一个登录界面(二) – .NET CORE(C#) WPF开发

微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏。

阅读导航

  1. 本文背景
  2. 代码实现
  3. 本文参考
  4. 源码

1. 本文背景

同上篇文章《少量代码设计一个登录界面》,本篇介绍另一种登录界面设计风格。

少量代码设计一个登录界面(二) – .NET CORE(C#) WPF开发

少量代码设计一个登录界面(二) – .NET CORE(C#) WPF开发

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库的样式文件:

<code><application>             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>
<resourcedictionary>
<resourcedictionary>
<resourcedictionary>
/<resourcedictionary.mergeddictionaries>
/<resourcedictionary>
/<application.resources>
/<application>/<code>

2.2 MainWindow.xaml 登录窗体

文件【MainWindow.xaml】,设计登录主界面,代码量很小,源码如下:

<code><window>        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>
<rectangle>
<rectangle.fill>
<lineargradientbrush>
<gradientstop>
<gradientstop>
<gradientstop>
/<lineargradientbrush>
/<rectangle.fill>
/<rectangle>
<stackpanel>
<label>
<stackpanel>
<textblock>/<textblock>
<textblock>/<textblock>
/<stackpanel>
<textblock>/<textblock>
<stackpanel>
<packicon>
<textbox>
/<stackpanel>
<stackpanel>
<packicon>
<passwordbox>
/<stackpanel>
<grid>
<checkbox>
<label>
/<grid>
<button>
<stackpanel>
<label>
<button>
<packicon>

/<button>
<button>
<packicon>
/<button>
<button>
<packicon>
/<button>
/<stackpanel>
/<stackpanel>
<button> Click="CloseWindow_Click">
<packicon>
/<button>
<stackpanel>
<textblock>
<textblock>
<textblock>
/<stackpanel>
/<grid>
/<window>/<code>

下面是后台代码:文件【MainWindow.xaml.cs】,关闭窗体、窗体移动等事件处理。

<code>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();
}
}
}/<code>

3.本文参考

  1. 视频一:C# WPF Material Design UI: Login Window,配套源码:Login1。
  2. C# WPF开源控件库《MaterialDesignInXAML》

4.源码

演示代码已全部奉上,为了方便演示,代码中的图片使用本站外链,代码可直接拷贝并按代码结构组织编译即可运行。


除非注明,文章均由 Dotnet9 整理发布,欢迎转载。

转载请注明本文地址:https://dotnet9.com/8091.html

欢迎扫描下方二维码关注 Dotnet9 的微信公众号,本站会及时推送最新技术文章


时间如流水,只能流去不流回!


分享到:


相關文章: