[WPF]MVVM模式下如何在後臺cs中呼叫繫結命令
阿新 • • 發佈:2021-07-22
https://blog.csdn.net/weixin_30896511/article/details/98689635
本文只談在後臺xaml.cs中的繫結,不討論前臺xaml中的繫結。程式碼為片段式,表意即可
按照命令的宣告及在後臺cs中的呼叫,直接上程式碼了。
1. VM中宣告
#region 繫結通知 /// <summary> /// 點選密碼重置時的通知 /// </summary> public RelayCommand Reset_Click { private set; get; } #endregion
2.VM中繫結函式
#region 建構函式 /// <summary> /// Initializes a new instance of the UsermanageViewModel class. /// </summary> public UserManageViewModel() { this.Reset_Click = new RelayCommand(PasswordReset); } #endregion
3.VM中建立對應函式
1 #region 繫結命令 2 private void PasswordReset() 3 { 4 MessageBox.Show("功能建設中"); 5 } 6 #endregionView Code
4.後臺程式碼xaml.cs中呼叫
((UserManageViewModel)this.DataContext).Reset_Click.Execute(null);View Code
轉載於:https://www.cnblogs.com/bloggonggy/archive/2013/06/01/3111806.html