wpf MVVM的简单绑定
程序员文章站
2024-02-02 11:17:22
...
1.前台部分:绑定用Bing
<TextBox Text="{Binding MyString}" Width="300" Height="30" VerticalContentAlignment="Center"></TextBox>
3.在ViewModel 写属性
#region 属性
private string myString;
public string MyString
{
get { return myString; }
set
{
myString = value;
this.RaisePropertyChanged("MyString");
}
}
#endregion
#region 构造函数
public MainWindowViewModels()
{
MyString = "Hollo Word";
}
属性快捷方法:propn + 2次Tab
构造函数快捷方法:ctor +Tab
4.在后台实例化下ViewModel
this.DataContext = new MainWindowViewModels();
5.运行结果
上一篇: 进度条函数封装