ReactiveUI,Xamarin Forms和XAML锁定的"Hello World"

Dam*_*yer 3 xaml xamarin.ios xamarin.android reactiveui xamarin

我正试图用Reactive UI和Xamarin Forms做一个hello world.

我创建了一个ViewModel(基于ReactiveObject),一个自定义页面(基于ReactiveContentPage)和一些XAML标记.

该页面有一个条目和一个绑定在一起的Label.当我运行它(在iOS和Android上)时,它似乎适用于键入的前几个字符,然后锁定.控制台给出了"在主线程上发生了太多"的警告.

我错过了什么?

这个项目在这里.

该模型

namespace XamarinFormsReactiveUIExample
{
    public class MyPageModel : ReactiveObject
    {
        private string _userName = "";
        public string UserName {
            get { return _userName; }
            set { this.RaiseAndSetIfChanged (ref _userName, value); }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这页纸

namespace XamarinFormsReactiveUIExample
{
    public partial class MyPage : ReactiveContentPage<MyPageModel>
    {
        public MyPage ()
        {
            InitializeComponent ();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

XAML

<?xml version="1.0" encoding="UTF-8"?>
<reactive:ReactiveContentPage 
x:TypeArguments="local:MyPageModel"
xmlns="http://xamarin.com/schemas/2014/forms" 
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
x:Class="XamarinFormsReactiveUIExample.MyPage"
xmlns:local="clr-namespace:XamarinFormsReactiveUIExample;assembly=XamarinFormsReactiveUIExample"
xmlns:reactive="clr-namespace:ReactiveUI.XamForms;assembly=ReactiveUI.XamForms">
    <reactive:ReactiveContentPage.BindingContext>
      <local:MyPageModel />
    </reactive:ReactiveContentPage.BindingContext>

     <reactive:ReactiveContentPage.Padding>
     <OnPlatform x:TypeArguments="Thickness"
                iOS="0, 150, 0, 0" />
     </reactive:ReactiveContentPage.Padding>

    <reactive:ReactiveContentPage.Content>
        <StackLayout>
            <Entry Text = "{Binding UserName}"></Entry>
            <Label Text = "{Binding UserName}"></Label>
        </StackLayout>
    </reactive:ReactiveContentPage.Content>
</reactive:ReactiveContentPage>
Run Code Online (Sandbox Code Playgroud)

Ana*_*tts 6

我不知道这可能是什么,除了Xamarin bug,ReactiveUI 这里没有任何事情.无论如何,你总是可以尝试用RxUI方式编写这些绑定:

<Entry x:Name="userNameEntry" />
<Label x:Name="userNameLabel" />
Run Code Online (Sandbox Code Playgroud)

然后,在构造函数中:

public MyPage ()
{
    InitializeComponent();
    this.ViewModel = new MyPageModel();

    this.Bind(ViewModel, vm => vm.UserName, v => v.userNameEntry.Text);
    this.OneWayBind(ViewModel, vm => vm.UserName, v => v.userNameLabel.Text);
}
Run Code Online (Sandbox Code Playgroud)