本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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.");
}
}
示例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;
}