当前位置: 首页>>代码示例>>C#>>正文


C# ExpressionObserver.UpdateRoot方法代码示例

本文整理汇总了C#中ExpressionObserver.UpdateRoot方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionObserver.UpdateRoot方法的具体用法?C# ExpressionObserver.UpdateRoot怎么用?C# ExpressionObserver.UpdateRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExpressionObserver的用法示例。


在下文中一共展示了ExpressionObserver.UpdateRoot方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Empty_Expression_Should_Track_Root

        public void Empty_Expression_Should_Track_Root()
        {
            var data = new Class1 { Foo = "foo" };
            var target = new ExpressionObserver(() => data.Foo, "");
            var result = new List<object>();

            target.Subscribe(x => result.Add(x));

            data.Foo = "bar";
            target.UpdateRoot();

            Assert.Equal(new[] { "foo", "bar" }, result);
        }
开发者ID:furesoft,项目名称:Perspex,代码行数:13,代码来源:ExpressionObserverTests_Property.cs

示例2: Can_Replace_Root

        public void Can_Replace_Root()
        {
            var first = new Class1 { Foo = "foo" };
            var second = new Class1 { Foo = "bar" };
            var root = first;
            var target = new ExpressionObserver(() => root, "Foo");
            var result = new List<object>();
            var sub = target.Subscribe(x => result.Add(x));

            root = second;
            target.UpdateRoot();
            root = null;
            target.UpdateRoot();

            Assert.Equal(new[] { "foo", "bar", PerspexProperty.UnsetValue }, result);

            Assert.Equal(0, first.SubscriptionCount);
            Assert.Equal(0, second.SubscriptionCount);
        }
开发者ID:furesoft,项目名称:Perspex,代码行数:19,代码来源:ExpressionObserverTests_Property.cs

示例3: CreateTemplatedParentSubject

        private ExpressionObserver CreateTemplatedParentSubject(
            IObservablePropertyBag target,
            string path)
        {
            Contract.Requires<ArgumentNullException>(target != null);

            var result = new ExpressionObserver(
                () => target.GetValue(Control.TemplatedParentProperty),
                path);

            if (target.GetValue(Control.TemplatedParentProperty) == null)
            {
                // TemplatedParent should only be set once, so only listen for the first non-null
                // value.
                target.GetObservable(Control.TemplatedParentProperty)
                    .Where(x => x != null)
                    .Take(1)
                    .Subscribe(x => result.UpdateRoot());
            }

            return result;
        }
开发者ID:Sergey-Terekhin,项目名称:Perspex,代码行数:22,代码来源:Binding.cs

示例4: CreateDataContextSubject

        private ExpressionObserver CreateDataContextSubject(
            IObservablePropertyBag target,
            string path,
            bool targetIsDataContext)
        {
            Contract.Requires<ArgumentNullException>(target != null);

            if (!targetIsDataContext)
            {
                var result = new ExpressionObserver(
                    () => target.GetValue(Control.DataContextProperty),
                    path);

                /// TODO: Instead of doing this, make the ExpressionObserver accept an "update"
                /// observable as doing it this way can will cause a leak in Binding as this 
                /// observable is never unsubscribed.
                target.GetObservable(Control.DataContextProperty).Subscribe(x =>
                    result.UpdateRoot());

                return result;
            }
            else
            {
                return new ExpressionObserver(
                    target.GetObservable(Visual.VisualParentProperty)
                          .OfType<IObservablePropertyBag>()
                          .Select(x => x.GetObservable(Control.DataContextProperty))
                          .Switch(),
                    path);
            }
        }
开发者ID:Sergey-Terekhin,项目名称:Perspex,代码行数:31,代码来源:Binding.cs

示例5: CreateTemplatedParentExpressionSubject

        private ExpressionObserver CreateTemplatedParentExpressionSubject(IObservablePropertyBag target)
        {
            var result = new ExpressionObserver(
                () => target.GetValue(Control.TemplatedParentProperty),
                GetExpression());

            if (target.GetValue(Control.TemplatedParentProperty) == null)
            {
                // TemplatedParent should only be set once, so only listen for the first non-null
                // value.
                target.GetObservable(Control.TemplatedParentProperty)
                    .Where(x => x != null)
                    .Take(1)
                    .Subscribe(x => result.UpdateRoot());
            }

            return result;
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:18,代码来源:Binding.cs

示例6: CreateDataContextExpressionSubject

        private ExpressionObserver CreateDataContextExpressionSubject(
            IObservablePropertyBag target,
            bool targetIsDataContext)
        {
            var dataContextHost = targetIsDataContext ?
                target.InheritanceParent as IObservablePropertyBag : target;

            if (dataContextHost != null)
            {
                var result = new ExpressionObserver(
                    () => dataContextHost.GetValue(Control.DataContextProperty),
                    GetExpression());
                dataContextHost.GetObservable(Control.DataContextProperty).Subscribe(x =>
                    result.UpdateRoot());
                return result;
            }
            else
            {
                throw new InvalidOperationException(
                    "Cannot bind to DataContext of object with no parent.");
            }
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:22,代码来源:Binding.cs

示例7: CreateDataContextExpressionSubject

        public ExpressionObserver CreateDataContextExpressionSubject(
            IObservablePropertyBag instance,
            PerspexProperty property)
        {
            var dataContextHost = property != Control.DataContextProperty ?
                instance :
                instance.InheritanceParent as IObservablePropertyBag;

            if (dataContextHost != null)
            {
                var result = new ExpressionObserver(
                    () => dataContextHost.GetValue(Control.DataContextProperty),
                    GetExpression());
                dataContextHost.GetObservable(Control.DataContextProperty).Subscribe(x =>
                    result.UpdateRoot());
                return result;
            }

            return null;
        }
开发者ID:strogo,项目名称:Perspex,代码行数:20,代码来源:Binding.cs


注:本文中的ExpressionObserver.UpdateRoot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。