首页 > 代码库 > 简单的mvvm light 应用
简单的mvvm light 应用
public class MainStudentModel:ViewModelBase
{
//实体
private StudentModel stu = new StudentModel();
public string StuName
{
get { return stu.Name; }
set
{
stu.Name = value;
// 激活属性
RaisePropertyChanged("StuName");
}
}
public string StuAddress
{
get { return stu.Address; }
set
{
stu.Address = value;
RaisePropertyChanged("StuAddress");
}
}
public RelayCommand ChangeStuCommand
{
get;
private set;
}
public MainStudentModel()
{
if (!IsInDesignMode)
{
stu = new StudentModel();
StuName = "xiaoming";
StuAddress = "朝阳区北苑二号院";
ChangeStuCommand=new RelayCommand(() =>
{
StuName = "taiyang";
StuAddress = "朝阳区duanwumen";
});
}
}
}
<TextBlock HorizontalAlignment="Left" Margin="80,66,0,0" TextWrapping="Wrap" Text="姓名" VerticalAlignment="Top"/>
<TextBox HorizontalAlignment="Left" Height="23" Margin="143,65,0,0" TextWrapping="Wrap" Text="{Binding StuName}" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.517,0.043"/>
<TextBlock HorizontalAlignment="Left" Margin="80,128,0,0" TextWrapping="Wrap" Text="地址" VerticalAlignment="Top"/>
<TextBox HorizontalAlignment="Left" Height="23" Margin="143,120,0,0" TextWrapping="Wrap" Text="{Binding StuAddress}" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.517,0.043"/>
<Button Content="显示" HorizontalAlignment="Left" Margin="143,240,0,0" VerticalAlignment="Top" Width="75" Command="{Binding ChangeStuCommand}"/>
public StudentView()
{
InitializeComponent();
//MainStudentModel
this.DataContext = new MainStudentModel();
}
简单的mvvm light 应用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。