Xamarin表单:无法将命令参数值从XAML传递给ViewModel

时间:2018-11-14 05:20:08

标签: xamarin.forms

public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
    var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));

    // Disable lock outs
    manager.UserLockoutEnabledByDefault = false;
    manager.MaxFailedAccessAttemptsBeforeLockout = 0; 
    manager.DefaultAccountLockoutTimeSpan = 0;

    //....
}

当我在XAML中附加了一个没有任何参数的命令事件时,上面的代码可以正常工作。

XAML:

ICommand _navigateAddNewAddress;
    public ICommand NavigateAddNewAddress => _navigateAddNewAddress ?? (_navigateAddNewAddress = new Command(async () =>
    {
        try
        {
            App.PushPage(AppPage.PROFILE_ADD_NEW_RESIDENTIAL_ADDRESS);
        }
        catch (Exception ex)
        {
            App.LogError(ex);
        }
    }));

请让我知道在c#代码中应该执行什么操作,以访问如下所示的命令参数值,

<Label.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding NavigateAddNewAddress}" ></TapGestureRecognizer>
                </Label.GestureRecognizers>

需要知道如何创建接受命令参数值的命令对象。以下带有“ args”参数的代码未提供该值,它给了我编译错误。

<Label.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding NavigateAddNewAddress}" CommandParameter={Binding CurrentAddress}></TapGestureRecognizer>
                </Label.GestureRecognizers>

请让我知道如何将命令参数值直接从XAML传递到ViewModel

0 个答案:

没有答案