public CreateFromPocoWindowViewModel()
        {
            // バインド方式:TwoWay
            // TwoWay: ToReactivePropertyAsSynchronized()
            FirstNameTwoWay = Poco.ToReactivePropertyAsSynchronized(x => x.FirstName)
                              .AddTo(Disposables);
            LastNameTwoWay = Poco.ToReactivePropertyAsSynchronized(x => x.LastName)
                             .AddTo(Disposables);

            // バインド方式:OneWay
            // OneWay: ObserveProperty().ToReadOnlyReactiveProperty()
            FirstNameOneWay = Poco.ObserveProperty(x => x.FirstName)
                              .ToReadOnlyReactiveProperty()
                              .AddTo(Disposables);
            LastNameOneWay = Poco.ObserveProperty(x => x.LastName)
                             .ToReadOnlyReactiveProperty()
                             .AddTo(Disposables);

            // バインド方式:OneWayToSource
            // OneWayToSource: ReactiveProperty.FromObject()
            FirstNameToSource = ReactiveProperty.FromObject(Poco, x => x.FirstName);
            //.AddTo(Disposables);  // TODO:不要?
            LastNameToSource = ReactiveProperty.FromObject(Poco, x => x.LastName);
            //.AddTo(Disposables);  // TODO:不要?
        }
    public void BindToTwoWayTestForRPSlim()
    {
        var target = new ReactivePropertySlim <string>();
        var obj    = new Poco();

        target.BindTo(obj,
                      o => o.Name,
                      mode: BindingMode.TwoWay,
                      targetUpdateTrigger: obj.ObserveProperty(o => o.Name).ToUnit());
        obj.Name.IsNull();

        target.Value = "Hello world";
        obj.Name.Is("Hello world");

        obj.Name = "tanaka";
        target.Value.Is("tanaka");
    }
Exemplo n.º 3
0
        public CreateFromPocoViewModel()
        {
            FirstNameTwoWay = Poco.ToReactivePropertyAsSynchronized(x => x.FirstName)
                              .AddTo(Disposables);
            LastNameTwoWay = Poco.ToReactivePropertyAsSynchronized(x => x.LastName)
                             .AddTo(Disposables);

            FirstNameOneWay = Poco.ObserveProperty(x => x.FirstName)
                              .ToReadOnlyReactivePropertySlim()
                              .AddTo(Disposables);
            LastNameOneWay = Poco.ObserveProperty(x => x.LastName)
                             .ToReadOnlyReactivePropertySlim()
                             .AddTo(Disposables);

            FirstNameOneWayToSource = ReactiveProperty.FromObject(Poco, x => x.FirstName);
            LastNameOneWayToSource  = ReactiveProperty.FromObject(Poco, x => x.LastName);
        }
    public void BindToOneWayToSourceTestForRPSlim()
    {
        var target = new ReactivePropertySlim <string>();
        var obj    = new Poco();

        target.BindTo(obj,
                      o => o.Name,
                      mode: BindingMode.OneWayToSource,
                      convertBack: s =>
        {
            Debug.WriteLine(s);
            return(s + "!");
        },
                      targetUpdateTrigger: obj.ObserveProperty(o => o.Name).ToUnit());

        obj.Name.IsNull();

        obj.Name = "Hello";
        target.Value.Is("Hello!");
    }
    public void BindToTwoWayConvertTestForRPSlim()
    {
        var target = new ReactivePropertySlim <int>();
        var obj    = new Poco();

        target.BindTo(obj,
                      o => o.Name,
                      mode: BindingMode.TwoWay,
                      convert: i => "value is " + i,
                      convertBack: s =>
        {
            Debug.WriteLine(s);
            return(int.Parse(s, NumberStyles.Integer));
        },
                      targetUpdateTrigger: obj.ObserveProperty(o => o.Name).ToUnit());

        obj.Name.Is("value is 0");

        target.Value = 1;
        obj.Name.Is("value is 1");

        obj.Name = "3";
        target.Value.Is(3);
    }