1、登錄界面設計要點
簡潔直觀的布局
登錄界面應避免復雜元素,突出核心功能。通常包含用戶名/郵箱輸入框、密碼輸入框、登錄按鈕及可選功能(如“記住我”“忘記密碼”)。保持表單字段不超過5個,減少用戶認知負擔。
清晰的視覺層次
通過尺寸、顏色對比區分主次操作。登錄按鈕使用高對比色(如藍色或綠色),次要操作(如注冊鏈接)采用低調設計。錯誤提示需醒目但友好,避免僅用紅色文字,可搭配圖標輔助說明。
響應式與無障礙設計
確保界面適配不同設備,輸入框尺寸足夠大(最小48x48px便于觸控)。 密碼輸入框需提供“顯示/隱藏”切換功能,提升可用性。
情感化微交互
登錄成功時使用短暫動畫(如勾選圖標+漸變跳轉),失敗時通過微震動提示錯誤字段。加載狀態顯示進度條或骨架屏,避免靜態“加載中”文字。
2、WPF 登錄界面設計?
布局與控件選擇
使用?Grid
?或?StackPanel
?布局,包含以下控件:
TextBox
?用于用戶名輸入(可添加?Watermark
?提示)。PasswordBox
?用于密碼輸入(隱藏明文)。CheckBox
?可選“記住密碼”功能。Button
?提交登錄(綁定命令或事件)。- 超鏈接控件(如“忘記密碼”或“注冊”)。
樣式與美觀性
- 使用?
Border
?和?CornerRadius
?實現圓角輸入框。 - 應用?
LinearGradientBrush
?實現背景漸變。 - 圖標集成:通過?
Image
?控件添加用戶/密碼圖標。 - 響應式設計:通過?
ViewBox
?或?RelativePanel
?適配不同窗口尺寸。
數據綁定與驗證
- 使用?
INotifyPropertyChanged
?實現雙向綁定(如用戶名/密碼屬性)。 - 輸入驗證:通過?
IDataErrorInfo
?或?ValidationRule
?檢查空輸入或格式錯誤。 - 錯誤提示:用?
ToolTip
?或?TextBlock
?顯示驗證消息。
3、UI界面設計
完成代碼如下,這就不每行代碼解析了:
<pu:WindowXx:Class="HQ.fResApp.LoginWindow"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:local="clr-namespace:HQ.fResApp"xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:pu="clr-namespace:Panuon.UI.Silver;assembly=Panuon.UI.Silver"Title=""Width="800"Height="450"pu:WindowXCaption.Header=" "pu:WindowXCaption.HideBasicButtons="True"BorderThickness="0"Loaded="WindowX_Loaded"MouseLeftButtonDown="MoveWindow_MouseLeftButtonDown"ResizeMode="NoResize"WindowStartupLocation="CenterScreen"mc:Ignorable="d"><Window.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></Window.Resources><Grid><Grid x:Name="signBlock"><Grid.ColumnDefinitions><ColumnDefinition /><ColumnDefinition Width="350" /></Grid.ColumnDefinitions><StackPanel Margin="20,-35,0,0"><LabelMargin="0,10"HorizontalAlignment="Left"VerticalAlignment="Top"Content="用戶登錄"FontFamily="Segoe UI Black"FontSize="20"Foreground="#2F4056" /><StackPanel Margin="0,45,0,0" Orientation="Horizontal"><materialDesign:PackIconWidth="30"Height="30"VerticalAlignment="Center"Foreground="#cccccc"Kind="Account" /><TextBoxx:Name="txtUName"Width="350"Margin="5"Padding="5,0,5,0"materialDesign:HintAssist.Foreground="#cccccc"materialDesign:HintAssist.Hint="輸入您的登錄賬號"FontSize="15" /></StackPanel><StackPanel Margin="0,33,0,0" Orientation="Horizontal"><materialDesign:PackIconWidth="30"Height="30"VerticalAlignment="Center"Foreground="#cccccc"Kind="Lock" /><PasswordBoxx:Name="txtUPwd"Width="350"Margin="5"Padding="5,0,5,0"materialDesign:HintAssist.Hint="輸入您的登錄密碼"FontSize="15" /></StackPanel><ButtonWidth="150"Height="50"Margin="-160,50,10,0"HorizontalAlignment="Center"materialDesign:ButtonAssist.CornerRadius="25"materialDesign:ShadowAssist.ShadowDepth="Depth2"Background="#5863f9"BorderBrush="#5863f9"Content="登錄"FontFamily="Impact"FontSize="18"IsDefault="True" /><ButtonWidth="150"Height="50"Margin="230,-50,10,0"HorizontalAlignment="Center"materialDesign:ButtonAssist.CornerRadius="25"materialDesign:ShadowAssist.ShadowDepth="Depth2"Background="#5863f9"BorderBrush="#5863f9"Click="CloseWindow_Click"Content="退出"FontFamily="Impact"FontSize="18"IsDefault="True" /><Grid Margin="0,50,20,0"><CheckBoxx:Name="chkRemember"Margin="5,10"VerticalAlignment="Center"Content="記住密碼"Cursor="Hand"FontSize="14"Foreground="#707070" /><TextBlockMargin="10"HorizontalAlignment="Right"VerticalAlignment="Center"Cursor="Hand"FontSize="14"Foreground="#5863f9"><Hyperlinkx:Name="btnForget"Click="BtnForget_Click"Foreground="#5863f9">忘記密碼?</Hyperlink></TextBlock></Grid></StackPanel><StackPanelGrid.Column="1"Margin="0,-13,0,0"Background="#5863f9"Orientation="Vertical"><ButtonPadding="10"HorizontalAlignment="Right"VerticalAlignment="Top"Background="{x:Null}"BorderBrush="{x:Null}"Click="CloseWindow_Click"Cursor="Hand"ToolTip="關閉"><materialDesign:PackIcon Kind="Close" /></Button><StackPanel Margin="0,50,0,0"><TextBlockHorizontalAlignment="Center"FontFamily="Champagne & Limousines"FontSize="48"FontWeight="Bold"Foreground="White"Text="蜀味正道" /><TextBlockWidth="280"Margin="0,50,0,0"HorizontalAlignment="Center"FontFamily="Champagne & Limousines"FontSize="22"Foreground="White"Text="蜀味正道,您的專屬管家!"TextAlignment="Center"TextWrapping="Wrap" /></StackPanel><StackPanel Margin="30,100,0,0" Orientation="Vertical"><StackPanel Orientation="Horizontal"><LabelMargin="10,0,0,0"VerticalAlignment="Center"Content="業務咨詢:"FontSize="15"Foreground="#F0F0F0" /><TextBlockx:Name="linkTel"VerticalAlignment="Center"FontFamily="Champagne & Limousines"FontSize="15"Foreground="#F0F0F0"TextAlignment="Center"TextWrapping="Wrap" /></StackPanel><StackPanel Orientation="Horizontal"><LabelMargin="10,0,0,0"VerticalAlignment="Center"Content="郵箱地址:"FontSize="15"Foreground="#F0F0F0" /><TextBlockx:Name="linkEmal"VerticalAlignment="Center"FontFamily="Champagne & Limousines"FontSize="15"Foreground="#F0F0F0"TextAlignment="Center"TextWrapping="Wrap" /></StackPanel><StackPanel Orientation="Horizontal"><LabelMargin="10,0,0,0"VerticalAlignment="Center"Content="公司官網:"FontSize="15"Foreground="#F0F0F0" /><TextBlockVerticalAlignment="Center"FontFamily="Champagne & Limousines"FontSize="15"Foreground="#F0F0F0"TextAlignment="Center"TextWrapping="Wrap"><Hyperlinkx:Name="LinkWeb"Click="LinkWeb_Click"Foreground="#F0F0F0"><TextBlock x:Name="LinkWebTxt" /></Hyperlink></TextBlock></StackPanel></StackPanel></StackPanel></Grid></Grid>
</pu:WindowX>
4、后臺業務邏輯代碼?
原創不易,打字截圖不易,走過路過,不要錯過,歡迎點贊,收藏,轉載,復制,抄襲,留言,動動你的金手指,早日實現財務自由!