0
我有一個基礎的呼叫BaseViewModel它由一個IList的集合,如下圖所示:收藏漸漸空虛當調用基類的方法
public class BaseViewModel
{
private IList<BrokenRule> _brokenRules = new List<BrokenRule>();
public IList<BrokenRule> BrokenRules
{
get { return _brokenRules; }
set { _brokenRules = value; }
}
public void ShowBrokenRules()
{
_brokenRulePresenter.Present(_brokenRules);
}
}
我的視圖模型UserEditViewModel從BaseViewModel繼承。驗證引擎驗證模型並填充破碎的規則。當我從具體類(UserEditViewModel)調用ShowBrokenRules時,那麼破壞的規則集合不包含任何內容。
UserEditViewModel保存方法:
private void Save(UserEditViewModel userEditViewModel)
{
bool isValid = ValidationEngine.Validate(this.UserViewModel); //
if (!isValid)
{
ShowBrokenRules();
}
}
我想原因是,裏面ShowBrokenRules方法_brokenRules指基類實現。我對麼?
UserEditViewModel類:
public class UserEditViewModel : BaseViewModel
{
private UserViewModel _userViewModel;
private void Save(UserEditViewModel userEditViewModel)
{
bool isValid = ValidationEngine.Validate(this.UserViewModel); // The UserViewModel.brokenrules is populated not the UserEditViewModel.brokenrules maybe that is the problem.
if (!isValid)
{
ShowBrokenRules();
}
}
是你的'UserEditViewModel'以某種方式覆蓋你的'ShowBrokenRules'方法? –
你可以顯示UserEditViewModel類嗎? –
我會推薦將'BrokenRules'公共訪問器傳遞給'Present'方法,而不是直接公開'_brokenRules'實現。 –