Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MvvmCross-单击viewmodel中的手柄按钮_C#_Ios_Mvvm - Fatal编程技术网

C# MvvmCross-单击viewmodel中的手柄按钮

C# MvvmCross-单击viewmodel中的手柄按钮,c#,ios,mvvm,C#,Ios,Mvvm,我是xamarin和mvvmcross的新手,我想从我的ios项目到我的viewmodel连接一个简单的按钮点击 using System; using MvvmCross.Binding.BindingContext; using MvvmCross.iOS.Views; using Colingual.Core.ViewModels; namespace Colingual.iOS { public partial class LoginView : MvxViewControll

我是xamarin和mvvmcross的新手,我想从我的ios项目到我的viewmodel连接一个简单的按钮点击

using System;
using MvvmCross.Binding.BindingContext;
using MvvmCross.iOS.Views;
using Colingual.Core.ViewModels;

namespace Colingual.iOS
{
    public partial class LoginView : MvxViewController
    {
        public LoginView() : base("LoginView", null)
        {
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            var set = this.CreateBindingSet<LoginView, LoginViewModel>();
            set.Bind(Username).To(vm => vm.Username);
            set.Bind(Password).To(vm => vm.Password);
            set.Bind(btnLogin).To(vm => vm.MyAwesomeCommand);
            set.Apply();
        }


        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }
    }
}

正如您所看到的,我有一个名为MyAwesomecommand的mvxCommand,但我想通过在另一个项目中单击按钮来处理一些逻辑。有人知道我应该做什么吗?

我已经做了更多的调查,并找到了一个新的答案

其想法是让您的mvxcommand getter返回一个新命令,该命令将该方法作为参数

单击按钮btnLogin时,可以访问viewmodel中的void DoStuff

using MvvmCross.Core.ViewModels;

namespace Colingual.Core.ViewModels
{
    public class LoginViewModel : MvxViewModel
    {
        readonly IAuthenticationService _authenticationService;

        public LoginViewModel(IAuthenticationService authenticationService)
        {
            _authenticationService = authenticationService;
        }

        string _username = string.Empty;
        public string Username
        {
            get { return _username; }
            set { SetProperty(ref _username, value); }
        }

        string _password = string.Empty;
        public string Password
        {
            get { return _password; }
            set { SetProperty(ref _password, value); }
        }



        public bool AuthenticateUser() {
            return true;
        }

        MvxCommand _myAwesomeCommand;


        public IMvxCommand MyAwesomeCommand
        {
            get
            {
                DoStuff();
                return _myAwesomeCommand;
            }
        }

        void DoStuff()
        {
            string test = string.Empty;
        }
    }
}
MvxCommand _myAwesomeCommand;

        public IMvxCommand MyAwesomeCommand
        {
            get { return new MvxCommand(DoStuff); }
        }

        void DoStuff()
        {
            string test = string.Empty;
        }