本文整理汇总了C#中System.Windows.Forms.Panel.SetDataContext方法的典型用法代码示例。如果您正苦于以下问题:C# Panel.SetDataContext方法的具体用法?C# Panel.SetDataContext怎么用?C# Panel.SetDataContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Panel
的用法示例。
在下文中一共展示了Panel.SetDataContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultiLevelDataContextInheritance1
public void MultiLevelDataContextInheritance1()
{
using(var form = new Form()) {
var panel = new Panel();
var button1 = new Button();
var button2 = new Button();
panel.Controls.Add(button1);
panel.Controls.Add(button2);
form.Controls.Add(panel);
form.SetDataContext("test");
Assert.That(button1.GetDataContext(), Is.EqualTo("test"));
Assert.That(button1.HasLocalDataContext(), Is.False);
form.SetDataContext("test2");
Assert.That(button1.GetDataContext(), Is.EqualTo("test2"));
Assert.That(button1.HasLocalDataContext(), Is.False);
button2.SetDataContext("button2");
form.ClearDataContext();
Assert.That(button1.GetDataContext(), Is.Null);
Assert.That(button1.HasLocalDataContext(), Is.False);
Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
Assert.That(button2.HasLocalDataContext(), Is.True);
form.SetDataContext("test2");
Assert.That(button1.GetDataContext(), Is.EqualTo("test2"));
Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
Assert.That(button2.HasLocalDataContext(), Is.True);
Assert.That(button1.HasLocalDataContext(), Is.False);
panel.SetDataContext("panel");
Assert.That(button1.GetDataContext(), Is.EqualTo("panel"));
Assert.That(button1.HasLocalDataContext(), Is.False);
Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
Assert.That(button2.HasLocalDataContext(), Is.True);
form.ClearDataContext();
Assert.That(panel.GetDataContext(), Is.EqualTo("panel"));
Assert.That(panel.HasLocalDataContext(), Is.True);
Assert.That(button1.GetDataContext(), Is.EqualTo("panel"));
Assert.That(button1.HasLocalDataContext(), Is.False);
Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
Assert.That(button2.HasLocalDataContext(), Is.True);
form.SetDataContext("test2");
Assert.That(panel.GetDataContext(), Is.EqualTo("panel"));
Assert.That(panel.HasLocalDataContext(), Is.True);
Assert.That(button1.GetDataContext(), Is.EqualTo("panel"));
Assert.That(button1.HasLocalDataContext(), Is.False);
Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
Assert.That(button2.HasLocalDataContext(), Is.True);
panel.ClearDataContext();
Assert.That(panel.GetDataContext(), Is.EqualTo("test2"));
Assert.That(panel.HasLocalDataContext(), Is.False);
Assert.That(button1.GetDataContext(), Is.EqualTo("test2"));
Assert.That(button1.HasLocalDataContext(), Is.False);
Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
Assert.That(button2.HasLocalDataContext(), Is.True);
form.Controls.Clear();
Assert.That(panel.GetDataContext(), Is.Null);
Assert.That(panel.HasLocalDataContext(), Is.False);
Assert.That(button1.GetDataContext(), Is.Null);
Assert.That(button1.HasLocalDataContext(), Is.False);
Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
Assert.That(button2.HasLocalDataContext(), Is.True);
panel.SetDataContext("panel");
Assert.That(button1.GetDataContext(), Is.EqualTo("panel"));
Assert.That(button1.HasLocalDataContext(), Is.False);
Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
Assert.That(button2.HasLocalDataContext(), Is.True);
panel.Controls.Clear();
Assert.That(button1.GetDataContext(), Is.Null);
Assert.That(button1.HasLocalDataContext(), Is.False);
Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
Assert.That(button2.HasLocalDataContext(), Is.True);
}
}
示例2: MultiLevelDataContextInheritance2
public void MultiLevelDataContextInheritance2()
{
using(var form = new Form()) {
var panel = new Panel();
var button = new Button();
panel.Controls.Add(button);
form.SetDataContext("test");
form.Controls.Add(panel);
Assert.That(button.GetDataContext(), Is.EqualTo("test"));
Assert.That(button.HasLocalDataContext(), Is.False);
form.SetDataContext("test2");
Assert.That(button.GetDataContext(), Is.EqualTo("test2"));
Assert.That(button.HasLocalDataContext(), Is.False);
panel.SetDataContext("panel");
Assert.That(button.GetDataContext(), Is.EqualTo("panel"));
Assert.That(button.HasLocalDataContext(), Is.False);
}
}
示例3: MultiLevelDataContextInheritance1
public void MultiLevelDataContextInheritance1()
{
using(var form = new Form()) {
var panel = new Panel();
var button1 = new Button();
button1.SetBinding("Text", new Binding());
panel.SetBinding("Tag", new Binding());
panel.Controls.Add(button1);
form.Controls.Add(panel);
form.SetDataContext("test");
Assert.That(button1.Text, Is.EqualTo("test"));
Assert.That(button1.HasLocalDataContext(), Is.False);
form.SetDataContext("test2");
Assert.That(button1.Text, Is.EqualTo("test2"));
Assert.That(button1.HasLocalDataContext(), Is.False);
form.ClearDataContext();
Assert.That(button1.Text, Is.EqualTo(string.Empty));
form.SetDataContext("test2");
Assert.That(panel.Tag, Is.EqualTo("test2"));
Assert.That(button1.Text, Is.EqualTo("test2"));
panel.SetDataContext("panel");
Assert.That(panel.Tag, Is.EqualTo("panel"));
Assert.That(button1.Text, Is.EqualTo("panel"));
form.ClearDataContext();
Assert.That(panel.Tag, Is.EqualTo("panel"));
Assert.That(button1.Text, Is.EqualTo("panel"));
form.SetDataContext("test2");
Assert.That(panel.Tag, Is.EqualTo("panel"));
Assert.That(button1.Text, Is.EqualTo("panel"));
panel.ClearDataContext();
Assert.That(panel.Tag, Is.EqualTo("test2"));
Assert.That(button1.Text, Is.EqualTo("test2"));
form.Controls.Clear();
Assert.That(panel.Tag, Is.Null);
Assert.That(button1.Text, Is.EqualTo(string.Empty));
}
}