本文整理汇总了C#中System.Windows.Controls.ContentPresenter.ReadLocalValue方法的典型用法代码示例。如果您正苦于以下问题:C# ContentPresenter.ReadLocalValue方法的具体用法?C# ContentPresenter.ReadLocalValue怎么用?C# ContentPresenter.ReadLocalValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ContentPresenter
的用法示例。
在下文中一共展示了ContentPresenter.ReadLocalValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindContentPresenterContent
public void BindContentPresenterContent ()
{
ContentPresenter presenter = new ContentPresenter ();
presenter.SetBinding (ContentPresenter.ContentProperty, new Binding ("Opacity"));
CustomControl c = new CustomControl { Content = presenter };
CreateAsyncTest (c,
() => {
c.DataContext = new Data { Opacity = 1.0 };
}, () => {
Assert.AreEqual (1.0, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#1");
Assert.AreEqual (1.0, presenter.Content, "#2");
c.DataContext = new Data { Opacity = 0.0 };
}, () => {
Assert.AreEqual (0.0, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#3");
Assert.AreEqual (0.0, presenter.Content, "#4");
}
);
}
示例2: DataContextTest7
public void DataContextTest7 ()
{
// A null content is copied to the datacontext too.
ContentPresenter presenter = new ContentPresenter ();
CreateAsyncTest (presenter,
() => {
presenter.Content = new object ();
}, () => {
Assert.AreEqual (presenter.Content, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#1");
presenter.Content = null;
}, () => {
Assert.AreEqual (null, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#2");
}
);
}
示例3: DataContextTest5b
public void DataContextTest5b ()
{
// When the ContentPresenter is in the tree, its DataContext gets set to ContentPresenter.Content
// when it is loaded
object o = new object ();
object content = new object ();
ContentPresenter c = new ContentPresenter { Content = content };
CreateAsyncTest (c,
() => {
Assert.AreEqual (content, c.DataContext, "#1");
Assert.AreEqual (content, c.ReadLocalValue (FrameworkElement.DataContextProperty), "#2");
}
);
}
示例4: DataContextTest5
public void DataContextTest5 ()
{
// When the ContentPresenter is in the tree, its DataContext gets set to ContentPresenter.Content
// when it is loaded
object o = new object ();
ContentPresenter c = new ContentPresenter { DataContext = o };
Assert.AreEqual (o, c.DataContext, "#1");
CreateAsyncTest (c,
() => {
Assert.IsNull (c.DataContext, "#2");
Assert.IsNull (c.ReadLocalValue (ContentPresenter.DataContextProperty), "#2b");
},
() => {
c.DataContext = o;
Assert.AreEqual (o, c.DataContext, "#3");
Assert.AreEqual (o, c.ReadLocalValue (ContentPresenter.DataContextProperty), "#3b");
},
() => Assert.AreEqual (o, c.DataContext, "#4")
);
}
示例5: DataContextTest2
public void DataContextTest2 ()
{
// Changing the content updates the datacontext
ContentPresenter c = new ContentPresenter ();
c.Content = new object ();
CreateAsyncTest (c,
() => {
Assert.AreEqual (c.Content, c.DataContext, "#1");
Assert.AreEqual (c.Content, c.ReadLocalValue (ContentPresenter.DataContextProperty), "#1b");
c.Content = new object ();
},
() => {
Assert.AreEqual (c.Content, c.DataContext, "#2");
Assert.AreEqual (c.Content, c.ReadLocalValue (ContentPresenter.DataContextProperty), "#2b");
}
);
}
示例6: DataContextTest_DataContextUpdatesAsync
public void DataContextTest_DataContextUpdatesAsync ()
{
var presenter = new ContentPresenter ();
presenter.SetBinding (ContentPresenter.DataContextProperty, new Binding ());
Assert.IsInstanceOfType<BindingExpression> (presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#1");
presenter.Content = new object ();
Assert.IsInstanceOfType<BindingExpression> (presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#2");
TestPanel.Children.Add (presenter);
Assert.IsInstanceOfType<BindingExpression> (presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#3");
Enqueue (() => {
Assert.AreSame (presenter.Content, presenter.ReadLocalValue (ContentPresenter.DataContextProperty), "#4");
});
EnqueueTestComplete ();
}