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

Enabe and Disable ActionsCommandBar Items #36

Open
katie1348 opened this issue Jul 7, 2016 · 1 comment
Open

Enabe and Disable ActionsCommandBar Items #36

katie1348 opened this issue Jul 7, 2016 · 1 comment

Comments

@katie1348
Copy link

Hi,

This is a feature request, as I don't think this is currently possible.

I would like to be able to programmatically enable and disable items in the ActionsCommandBar, so that items can be made available from the ViewModel as the model changes.

Thanks

K

@javitosanchez
Copy link
Collaborator

Right now you can control your ActionsCommandBar items visibility with the canExecute delegate of the action item Command.

if (button.Command?.CanExecute(button?.CommandParameter) == true)
{
    button.Visibility = Visibility.Visible;
}
else
{
    button.Visibility = Visibility.Collapsed;
}

For example, all of our actions, handle the canExecute determining if the parameter is null or not:

public static ICommand Mailto
{
    get
    {
        return new RelayCommand<string>(async mail =>
        {
            if (!string.IsNullOrEmpty(mail))
            {
                await Launcher.LaunchUriAsync(new Uri(string.Format("mailto:{0}", mail)));
            }
        }, **(mail => !string.IsNullOrEmpty(mail)));**
    }
}

We did this because it's easier to hide a button than disabling and applying styles to it.

Works for you?

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

No branches or pull requests

2 participants