ReactiveUI Xamarin.ios引导器用于clean应用程序启动

ReactiveUI Xamarin.ios引导器用于clean应用程序启动,xamarin.ios,reactiveui,Xamarin.ios,Reactiveui,我一直在寻找一些关于如何在反应式ui中启动xamarin.ios应用程序的示例。我也是Xamarin.ios的新手,所以我可能错过了一个关键的步骤。我发现的所有示例都是旧的、过时的,或者需要太多的手动设置。我希望通过调用RoutedViewHost解决UIViewController的方式进行设置,UIViewController目前无法工作,我会出现黑屏。我想没有简单的方法把事情联系起来,但我想先检查一下,然后问问题 类似于如何引导Xamarin.forms项目,以及下面的代码如何在Xamar

我一直在寻找一些关于如何在反应式ui中启动xamarin.ios应用程序的示例。我也是Xamarin.ios的新手,所以我可能错过了一个关键的步骤。我发现的所有示例都是旧的、过时的,或者需要太多的手动设置。我希望通过调用RoutedViewHost解决UIViewController的方式进行设置,UIViewController目前无法工作,我会出现黑屏。我想没有简单的方法把事情联系起来,但我想先检查一下,然后问问题

类似于如何引导Xamarin.forms项目,以及下面的代码如何在Xamarin.forms中成功运行,我也想在native.ios中启动一个。。到目前为止,我无法让绑定和路由在初始应用程序启动时工作。我在AppDelegate中有以下代码

cs

AppBootstrapper是一个反应对象,是一个Screen对象,我尝试注册一个简单的LoginView供初学者测试。视图位于序列图像板中,分配给LoginViewController

cs

private void InitializeIoC()
{
Locator.CurrentMutable.RegisterConstant(this,typeof(IScreen));
}
私有void RegisterViews()
{
Locator.CurrentMutable.Register(()=>new LoginViewController(),typeof(IViewFor));
}
私有void registerOutableViewModals()
{
Locator.CurrentMutable.Register(()=>new LoginViewModel(),typeof(IRoutableViewModel),typeof(LoginViewModel).FullName);
}
公共UIViewController CreateMainView()
{
返回新的RoutedViewHost();
}

public分部类LoginViewController:ReactiveViewController
{
公共登录查看控制器()
{
ViewModel=新的LoginViewModel();
此。当激活时(一次性=>
{
这个.bind命令(ViewModel,x=>x.LoginCommand,x=>x.btnLogin)
.一次性使用(一次性使用);
this.Bind(ViewModel,x=>x.Username,x=>x.txtPassword.Text)
.一次性使用(一次性使用);
this.Bind(ViewModel,x=>x.Password,x=>x.txtPassword.Text)
.一次性使用(一次性使用);
这个.OneWayBind(ViewModel,x=>x.Warning,x=>x.lblWarning.Text)
.一次性使用(一次性使用);
此.OneWayBind(ViewModel,x=>x.IsExecuteEnabled,x=>x.btnLogin.Enabled)
.一次性使用(一次性使用);
});
}

public类LoginViewModel:ReactiveObject,IRoutableViewModel
{
公共字符串UrlPathSegment=>“登录”;
公共IScreen主机屏幕{get;}
公共登录视图模型(IScreen screen=null)
{
HostScreen=screen??Locator.Current.GetService();
LoginCommand=ReactiveCommand.CreateFromTask(异步=>Login());
此.whenyValue(x=>x.Username,x=>x.Password,x=>x.LoginCommand,
(用户、通行证、命令)=>
!string.IsNullOrEmpty(用户)&&
!string.IsNullOrEmpty(通过)&&
user.Length>=3&&
!IsCommandExecuting&&
!\u禁用登录按钮)
.DistinctUntilChanged()
.ToProperty(这个,x=>x.IsExecuteEnabled,out _IsExecuteEnabled);
LoginCommand.i执行
.ToProperty(this,x=>x.IsCommandExecuting,out\u IsCommandExecuting);
}

我注意到的一件事是,您将
ReactiveViewController
作为
RootViewController
传递,我认为它应该是
RoutedViewHost
应该是
UINavigationController
所以我注意到的一件事是,您将
ReactiveViewController
作为
RootViewController传递我认为应该是
RoutedViewHost
应该是
UINavigationController
var bootstrap = new AppBootstrapper(); 
var rootViewController = bootstrap.CreateMainView(); 
Window.RootViewController = rootViewController; 
Window.MakeKeyAndVisible();
public class AppBootstrapper: ReactiveObject, IScreen

    public AppBootstrapper()
    {
        _routingState = new RoutingState();
        InitializeIoC();            
        RegisterViews();
        RegisterRoutableViewModals();

        _routingState.Navigate.Execute(new LoginViewModel(this));
private void InitializeIoC()
{
    Locator.CurrentMutable.RegisterConstant(this, typeof(IScreen));
}

private void RegisterViews()
{
    Locator.CurrentMutable.Register(() => new LoginViewController(), typeof(IViewFor<LoginViewModel>));
}

private void RegisterRoutableViewModals()
{
    Locator.CurrentMutable.Register(() => new LoginViewModel(), typeof(IRoutableViewModel), typeof(LoginViewModel).FullName);
}

public UIViewController CreateMainView()
{
    return new RoutedViewHost();
}
public partial class LoginViewController : ReactiveViewController<LoginViewModel>
    {
        public LoginViewController()
        {
            ViewModel = new LoginViewModel();

            this.WhenActivated(disposables =>
            {
                this.BindCommand(ViewModel, x => x.LoginCommand, x => x.btnLogin)
                    .DisposeWith(disposables);
                this.Bind(ViewModel, x => x.Username, x => x.txtPassword.Text)
                    .DisposeWith(disposables);
                this.Bind(ViewModel, x => x.Password, x => x.txtPassword.Text)
                    .DisposeWith(disposables);
                this.OneWayBind(ViewModel, x => x.Warning, x => x.lblWarning.Text)
                    .DisposeWith(disposables);
                this.OneWayBind(ViewModel, x => x.IsExecuteEnabled, x => x.btnLogin.Enabled)
                    .DisposeWith(disposables);
            });
        }
 public class LoginViewModel: ReactiveObject, IRoutableViewModel
    {
        public string UrlPathSegment => "Login";

        public IScreen HostScreen { get; }

        public LoginViewModel(IScreen screen = null)
        {
            HostScreen = screen ?? Locator.Current.GetService<IScreen>();

            LoginCommand = ReactiveCommand.CreateFromTask(async => Login());

            this.WhenAnyValue(x => x.Username, x => x.Password, x => x.LoginCommand,
                    (user, pass, command) =>
                        !string.IsNullOrEmpty(user) &&
                        !string.IsNullOrEmpty(pass) &&
                        user.Length >= 3 &&
                        !IsCommandExecuting &&
                        !_disableLoginButton)
                .DistinctUntilChanged()
                .ToProperty(this, x => x.IsExecuteEnabled, out _isExecuteEnabled);

            LoginCommand.IsExecuting
                .ToProperty(this, x => x.IsCommandExecuting, out _isCommandExecuting);
        }