开发者

Caliburn Can{Action} not getting updated on 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);
        }

    }

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:

NotifyOfPropertyChange(() => CanAddAllToProfile);

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 named AddAllToProfile). So if it works, why are you not doing that?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜