欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

入坑之WPF使用MaterialDesign【第一天】登录界面

程序员文章站 2022-05-30 23:13:14
...

参考文章:https://blog.csdn.net/YouyoMei/article/details/99996450

效果图入坑之WPF使用MaterialDesign【第一天】登录界面

初次使用WPF

NuGet,
入坑之WPF使用MaterialDesign【第一天】登录界面
安装
入坑之WPF使用MaterialDesign【第一天】登录界面
app.xaml加入

<ResourceDictionary.MergedDictionaries>
<!-- 在此引用资源文件-->
                <!--  MahApps  -->
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
                <!--  Material Design,整体界面颜色  -->
                <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.LightBlue.xaml" />            
 </ResourceDictionary.MergedDictionaries>

windows.xaml修改

<Controls:MetroWindow
                      xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"                       
                      xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
 ……
 </Controls:MetroWindow>

windows.cs修改

public partial class Window1 : MetroWindow

TEXTBOX控件有自验证功能,需要绑定,绑定时Path不能随便设置,需要有对应的控件或者实例,否则无效。
如下,绑定的是 Name,

<TextBox.Text>
            <Binding Path="Name" UpdateSourceTrigger="PropertyChanged">
                <Binding.ValidationRules>
                    <domain:NotEmptyValidationRule ValidatesOnTargetUpdated="True" />
                </Binding.ValidationRules>
            </Binding>
</TextBox.Text>

对应的实例为:

public class Person
{
	string name = string.Empty;
	string pw = string.Empty;
	public string Name
	{
		get { return name; }
		set { name = value; }
	}
	public string Password
	{
		get { return pw; }
		set { pw = value; }
	}
}

初始化的时候绑定

Person p = new Person();
p.Name = txtName.Text.Trim();
p.Password = txtPass.Password;

爬了一整天。

相关标签: WPF MaterialDesign