少量代碼設計一個登錄界面 - .NET CORE(C#) WPF開發(fā)閱讀導航 1. 本文背景" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁 > 營銷資訊 > 網(wǎng)站運營 > 少量代碼設計一個登錄界面 - .NET CORE(C#) WPF開發(fā)

少量代碼設計一個登錄界面 - .NET CORE(C#) WPF開發(fā)

時間:2023-09-05 17:54:02 | 來源:網(wǎng)站運營

時間:2023-09-05 17:54:02 來源:網(wǎng)站運營

少量代碼設計一個登錄界面 - .NET CORE(C#) WPF開發(fā):
微信公眾號:Dotnet9,網(wǎng)站:Dotnet9,問題或建議:請網(wǎng)站留言, 如果對您有所幫助:歡迎贊賞。

少量代碼設計一個登錄界面 - .NET CORE(C#) WPF開發(fā)

閱讀導航 1. 本文背景 2. 代碼實現(xiàn) 3. 本文參考 4. 源碼

1. 本文背景

繼續(xù) MaterialDesignThemes 開源控件庫學習,本文簡單使用輸入控件的水印附加屬性:materialDesign:HintAssist.Hint。













2. 代碼實現(xiàn)

使用 .NET CORE 3.1 創(chuàng)建名為 “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】節(jié)點增加 MaterialDesignThemes庫的樣式文件:

<Application x:Class="Login.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Login" 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.Blue.xaml" /> <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Indigo.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="登錄" Height="500" Width="350" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowStyle="None" MouseLeftButtonDown="MoveWindow_MouseLeftButtonDown" FontFamily="Segoe UI Emoji"> <Grid> <Rectangle Height="280" VerticalAlignment="Top"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF2281D1"/> <GradientStop Color="#FF34268A" Offset="1"/> <GradientStop Color="#FF33288B" Offset="0.546"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Rectangle Width="280" Height="240" VerticalAlignment="Bottom" Margin="0,80" RadiusY="10" RadiusX="10" Fill="White"> <Rectangle.Effect> <DropShadowEffect BlurRadius="15" Direction="0" RenderingBias="Quality" ShadowDepth="1" Color="#FFBBBBBB"/> </Rectangle.Effect> </Rectangle> <Grid VerticalAlignment="Bottom" Margin="35,80" Height="240"> <Label Content="登錄" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="5" Foreground="Gray" FontSize="18"/> <StackPanel VerticalAlignment="Center" Margin="15"> <TextBox Margin="0,10" materialDesign:HintAssist.Hint="賬號" Style="{StaticResource MaterialDesignFloatingHintTextBox}" FontFamily="Champagne &amp; Limousines" FontSize="18"/> <PasswordBox Margin="0,10" materialDesign:HintAssist.Hint="密碼" Style="{StaticResource MaterialDesignFloatingHintPasswordBox}" FontFamily="Champagne &amp; Limousines" FontSize="18"/> </StackPanel> </Grid> <Button Width="150" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,65" Content="LOGIN"/> <TextBlock Text="忘記密碼?" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="30" Foreground="Gray" Cursor="Hand"/> <Button HorizontalAlignment="Right" VerticalAlignment="Top" Background="{x:Null}" BorderBrush="{x:Null}" Click="Close_Click"> <materialDesign:PackIcon Kind="Close"/> </Button> <Image Source="https://img.dotnet9.com/logo-foot.png" Width="100" Height="100" VerticalAlignment="Top" Margin="30"/> </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 MoveWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DragMove(); } private void Close_Click(object sender, RoutedEventArgs e) { this.Close(); } }}

3.本文參考

  1. 視頻一:C# WPF Material Design UI: Login Window,配套源碼:Login2。
  2. C# WPF開源控件庫《MaterialDesignInXAML》

4.源碼

演示代碼已全部奉上,為了方便演示,代碼中的圖片使用本站外鏈,代碼可直接拷貝并按代碼結構組織編譯即可運行。


除非注明,文章均由 Dotnet9 整理發(fā)布,歡迎轉(zhuǎn)載。
轉(zhuǎn)載請注明本文地址:https://dotnet9.com/8078.html
歡迎掃描下方二維碼關注 Dotnet9 的微信公眾號,本站會及時推送最新技術文章
http://weixin.qq.com/r/UETq8gvErVbSrU_R9xFC (二維碼自動識別)





時間如流水,只能流去不流回!

點擊《【閱讀原文】》,【Dotnet9的博客】站點還有更多技術類文章等著您哦?。。?br>
此刻順便為我點個《【再看】》可好?

關鍵詞:界面,設計

74
73
25
news

版權所有? 億企邦 1997-2025 保留一切法律許可權利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點擊下載Chrome瀏覽器
關閉