Caliburn Can{Action} 未在 Refresh() 上更新
public void AddProfile()
{
//Add conventions for DX Components.
Profile newProfile = new Profile()
{
Description = "New Profile",
DisplayOrder = decimal.MaxValue,
IsActive = true,
IsDefault = false,
IsSelected = true,
ProfileId = 0
};
EditProfileViewModel profile = new EditProfileViewModel(true) { Profile = newProfile };
if (windowManager.ShowDialog(profile,null ) ?? false) // ?? means (coallesce so if null use false value) the line means, if dialog returns true...
{
Profiles.Add(profile.Profile);
NotifyOfPropertyChange(string.Empty);
}
}
可以添加按钮的代码是这样的。
public bool CanAddAllToProfile
{
get
{
var p = Profiles.Where(x => x.IsSelected).FirstOrDefault();
if (p == null)
return false;
if (AvailableModules.Count() == 0)
return false;
return true;
}
}
public void AddAllToProfile()
{
var p = Profiles.Where(x => x.IsSelected).FirstOrDefault();
if (p == null)
return;
foreach (var m in AvailableModules)
p.Modules.Add(m);
NotifyOfPropertyChange(string.Empty);
}
如果我编写这样的代码,则 CanAddAllToProfile get 不会被执行。
如果我执行 NotifyOfPropertyChange(() => CanAddAllToProfile) 它有效
我也尝试过 Refresh();
我从 Screen 继承视图模型,任何想法我都有一堆其他需要执行的 CanExecuteBindings。显然这是可以解决的,但我想知道我是否做错了什么。
public void AddProfile()
{
//Add conventions for DX Components.
Profile newProfile = new Profile()
{
Description = "New Profile",
DisplayOrder = decimal.MaxValue,
IsActive = true,
IsDefault = false,
IsSelected = true,
ProfileId = 0
};
EditProfileViewModel profile = new EditProfileViewModel(true) { Profile = newProfile };
if (windowManager.ShowDialog(profile,null ) ?? false) // ?? means (coallesce so if null use false value) the line means, if dialog returns true...
{
Profiles.Add(profile.Profile);
NotifyOfPropertyChange(string.Empty);
}
}
The code for the can add buttons is like this.
public bool CanAddAllToProfile
{
get
{
var p = Profiles.Where(x => x.IsSelected).FirstOrDefault();
if (p == null)
return false;
if (AvailableModules.Count() == 0)
return false;
return true;
}
}
public void AddAllToProfile()
{
var p = Profiles.Where(x => x.IsSelected).FirstOrDefault();
if (p == null)
return;
foreach (var m in AvailableModules)
p.Modules.Add(m);
NotifyOfPropertyChange(string.Empty);
}
The CanAddAllToProfile get does not get executed if I write the code like this.
if I do a NotifyOfPropertyChange(() => CanAddAllToProfile) it works
I also tried Refresh();
I am inheriting the viewmodel from Screen any ideas I have a bunch of other CanExecuteBindings that need to be executed. Obviously this can be worked around but I am wondering if I am doing something wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您刚刚给出了问题的答案:
这是告诉绑定基础结构它应该调用
CanAddAllToProfile
并更新绑定到该属性的任何内容的适当方法(例如名为AddAllToProfile 的按钮) )。那么,如果它有效,你为什么不这样做呢?
You just gave the answer in your question:
That is the appropriate way to tell the binding infrastructure that it should call
CanAddAllToProfile
and update anything that is binding to that property (such as the button namedAddAllToProfile
). So if it works, why are you not doing that?