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.
You just gave the answer in your question:
That is the appropriate way to tell the binding infrastructure that it should call
CanAddAllToProfileand update anything that is binding to that property (such as the button namedAddAllToProfile). So if it works, why are you not doing that?