Tôi đang cố gắng chuyển CommandParameter
cho phương thức trong ViewModel
của mình. Cách thực hiện việc này?Truyền tham số lệnh vào phương thức trong ViewModel trong WPF?
private void Open(object sender)
{
if (sender==this.objMainWindow.btnHistory)
{
objMainWindow.Container.Child = objHistory;
}
if (sender == this.objMainWindow.btnNew_Item)
{
objMainWindow.Container.Child = objNewItem;
}
if (sender == this.objMainWindow.btnSide_Effects)
{
objMainWindow.Container.Child = objSideEffect;
}
}
Đây là meyhod tôi trong ViewModel
mà tôi muốn vượt qua CommandParameter
. Tôi sử dụng nút CommandParameter
cho nút.
cách sử dụng RaisePropertyChanged()? – Mahsa
Đó chỉ là việc thực hiện thông báo thay đổi tài sản MVVM Lite sử dụng mà bạn có thể thêm thông qua NuGet (lấy được mô hình xem của bạn từ ViewModelBase). Có rất nhiều cách khác để làm điều đó mặc dù bao gồm cả những người được hiển thị [ở đây] (https://msdn.microsoft.com/en-us/library/vstudio/ms743695 (v = vs.100) .aspx) và [ở đây] (http://stackoverflow.com/questions/1315621/implementing-inotifypropertychanged-does-a-better-way-exist). –