Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional methods with parameters as actions? #147

Open
vgist1 opened this issue Jul 20, 2020 · 6 comments
Open

Conditional methods with parameters as actions? #147

vgist1 opened this issue Jul 20, 2020 · 6 comments

Comments

@vgist1
Copy link

vgist1 commented Jul 20, 2020

Hi @canton7,

Thanks for this awesome library, I have been using it and I just love how simple and powerful it is.

On caliburn you can use methods with parameters for conditions(for reference: https://caliburnmicro.com/documentation/actions#action-parameters), say

public bool CanDoSomething(string name)
{
    return !string.IsNullOrWhiteSpace(name);
}

public void DoSomething(string name)
{
    // do something
}

From what I read on the documentation with Stylet that is not possible with a method or taking a parameter.

I could probably do a hacky approach which would involve binding 2 properties to achieve something close to the above but its no ideal.

Do you have any plans on adding that into Stylet or have I missed something and that is indeed possible?

@vgist1 vgist1 changed the title Methods as actions? Conditional methods with parameters as actions? Jul 20, 2020
@canton7
Copy link
Owner

canton7 commented Jul 20, 2020

Looks like they added guard methods since I last used it.

The tricky bit here is knowing when the re-evaluate the guard method. With guard properties we use INPC, but that doesn't work for methods. It looks like Caliburn.Micro used cal:Parameter, which adds a bunch of additional complexity.

If you can come up with a nice way of implementing something similar to this, I'm all ears. This might also be useful

@canton7
Copy link
Owner

canton7 commented Jul 20, 2020

Actually, if the button (or whatever) evaluates ICommand.CanExecuted whenever its CommandParameter property changes, that could work. I'll have to experiment.

@canton7
Copy link
Owner

canton7 commented Jul 20, 2020

Ah no, doesn't look like that works, sadly.

@vgist1
Copy link
Author

vgist1 commented Jul 20, 2020

Looks like they added guard methods since I last used it.

The tricky bit here is knowing when the re-evaluate the guard method. With guard properties we use INPC, but that doesn't work for methods. It looks like Caliburn.Micro used cal:Parameter, which adds a bunch of additional complexity.

If you can come up with a nice way of implementing something similar to this, I'm all ears. This might also be useful

I would do that if I had the knowledge but I am just a beginner and I am afraid that would be too much for me to do at this moment.

I am a student and am just learning the principles of mvvm, wpf, etc.

But thank you very much for taking the time and answer.

@WillBellJr
Copy link

I agree, thanks Canton7 for taking the time to look into this suggestion.

I'm not new to MVVM, but always struggled with what I was using (mostly DevExpress MVVM) - I've been successfully using Stylet_ now for a couple of projects, AND I have to say, Stylet has finally made using MVVM with my WPF apps so much easier.

I look forward to ANY additions to this project!

@canton7
Copy link
Owner

canton7 commented Sep 3, 2020

Heh, maybe Action can subscribe to changes on the button's CommandParameter. That would be a very hacky but probably quite neat way of doing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants