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);
}
}
canaddボタンのコードはこんな感じです。
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);
}
このようなコードを記述した場合、CanAddAllToProfilegetは実行されません。
NotifyOfPropertyChange(()=> CanAddAllToProfile)を実行すると、機能します
また、Refresh();を試しました。
実行する必要のある他のCanExecuteBindingがたくさんあるアイデアは、Screenからビューモデルを継承しています。明らかにこれは回避できますが、何か間違ったことをしているのではないかと思います。