Demo:

Your time is precious. If you don't want to read wordy text, you can directly pull it to the end of the text and download the source code!
1. new project
Webmaster development environment:
- VS 2019 Enterprise Edition 16.70
- .NET 5 Preview 5
There is no difference between the. NET 5 WPF project template and the. NET Core 3.1 WPF project template. After creating the project, NuGet introduces the MaterialDesignThemes library:

2. Introduce styles
The Demo consists of only one xaml file and xaml.cs file. In order to facilitate the collection of WPF interface design effects later, they are placed in the open source project TerminalMACS.ManagerForWPF, so control style references are directly added in FoodAppLoginView.xaml:
<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.Amber.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
3. Control animation effects
See the GIF animation above. When the login window loads, elements such as the username input box, password input box, remember password, and the right background picture have animation effects. Each part of the code structure is similar, such as the following username input box code:
<!--#region User name textblox-->
<materialDesign:TransitioningContent Grid.Row="2" Margin="90,20,00,0" HorizontalAlignment="Left">
<materialDesign:TransitioningContent.OpeningEffects>
<materialDesign:TransitionEffect Kind="SlideInFromLeft" Duration="0:0:2"/>
</materialDesign:TransitioningContent.OpeningEffects>
<StackPanel Style="{StaticResource setVisibilityBasedLogin}" Orientation="Horizontal">
<materialDesign:PackIcon Kind="Account" Width="16" Height="16" VerticalAlignment="Center"
Margin="0,5,10,0" Foreground="{Binding ElementName=NameTextBox, Path=BorderBrush}"/>
<TextBox x:Name="NameTextBox" Width="140" materialDesign:HintAssist.Hint="{markup:I18n {x:Static i18NResources:Language.FoodAppLoginView_UserName}}"
Style="{StaticResource MaterialDesignFloatingHintTextBox}"/>
</StackPanel>
</materialDesign:TransitioningContent>
<!--#endregion-->
The TransioningContent component of the open source control MD is used, and the Kind property of TransionEffect sets the animation direction of the control.
4. Simulated login
Login button layout code:
<!--#region control panel-->
<materialDesign:TransitioningContent Grid.Row="4" Margin="40,20,0,0">
<materialDesign:TransitioningContent.OpeningEffects>
<materialDesign:TransitionEffect Kind="SlideInFromBottom" Duration="0:0:2"/>
</materialDesign:TransitioningContent.OpeningEffects>
<StackPanel Style="{StaticResource setVisibilityBasedLogin}" Orientation="Horizontal" HorizontalAlignment="Center">
<CheckBox Content="{markup:I18n {x:Static i18NResources:Language.FoodAppLoginView_RememberMe}}"/>
<Button Style="{StaticResource MaterialDesignRaisedButton}"
Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}"
materialDesign:ButtonAssist.CornerRadius="20"
Width="80" Height="40" Margin="120,0,0,0"
Content="{markup:I18n {x:Static i18NResources:Language.FoodAppLoginView_Login}}"/>
</StackPanel>
</materialDesign:TransitioningContent>
<!--#endregion-->
When clicking login, the waiting dialog box opens (the click is bound to materialDesign:DialogHost.OpenDialogCommand), and login logic is processed in the open and close events of the waiting dialog box.
private async Task<bool> ValidateCreds()
{
// 模拟登录
// 你可以发送登录信息到服务器,得到认证回馈
await Task.Delay(TimeSpan.FromSeconds(2));
Random gen = new Random(DateTime.Now.Millisecond);
int loginProb = gen.Next(100);
return loginProb <= 20;
}
private async void OpenCB_DialogOpened(object sender, MaterialDesignThemes.Wpf.DialogOpenedEventArgs eventArgs)
{
try
{
this.IsJustStarted = true;
this.LoginStatusmsg = "";
bool isLoggedIn = await ValidateCreds();
if (isLoggedIn)
{
// 需要关闭登录对话框并显示主窗口
eventArgs.Session.Close(true);
}
else
{
// 登录失败,设置false作为参数
eventArgs.Session.Close(false);
}
}
catch (Exception)
{
//throw;
}
}
private void ClosingCB_DialogClosing(object sender, MaterialDesignThemes.Wpf.DialogClosingEventArgs eventArgs)
{
if (eventArgs.Parameter == null)
{
return;
}
IsLoggedIn = (bool)eventArgs.Parameter;
IsJustStarted = false;
if(IsLoggedIn)
{
this.LoginStatusmsg = I18nManager.Instance.Get(I18nResources.Language.FoodAppLoginView_Success).ToString();
}
else
{
this.LoginStatusmsg = I18nManager.Instance.Get(I18nResources.Language.FoodAppLoginView_Fail).ToString();
}
}
Simulate login logic in the event waiting for the dialog box to open.
When waiting for the dialog box to close, make the interface response message.
5. source download
Only some key code is posted on it, and the source code has been placed on GitHub.