當前位置: 首頁>>代碼示例>>C#>>正文


C# Form.ClearDataContext方法代碼示例

本文整理匯總了C#中System.Windows.Forms.Form.ClearDataContext方法的典型用法代碼示例。如果您正苦於以下問題:C# Form.ClearDataContext方法的具體用法?C# Form.ClearDataContext怎麽用?C# Form.ClearDataContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Forms.Form的用法示例。


在下文中一共展示了Form.ClearDataContext方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ChangeInheritedDataContext

        public void ChangeInheritedDataContext()
        {
            using(var form = new Form()) {
                var button1 = new Button();
                var button2 = new Button();
                form.Controls.Add(button1);
                form.Controls.Add(button2);
                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("test");
                Assert.That(button1.GetDataContext(), Is.EqualTo("test"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                form.Controls.Remove(button1);
                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.Controls.Remove(button2);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);
            }
        }
開發者ID:VitalyTVA,項目名稱:WinMVVM,代碼行數:38,代碼來源:DataContextProviderTests.cs

示例2: 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));
            }
        }
開發者ID:VitalyTVA,項目名稱:WinMVVM,代碼行數:45,代碼來源:BindingOperationsTests.cs

示例3: 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);
            }
        }
開發者ID:VitalyTVA,項目名稱:WinMVVM,代碼行數:82,代碼來源:DataContextProviderTests.cs

示例4: InheritedDataContextBinding_BindAfterAddToTree

        public void InheritedDataContextBinding_BindAfterAddToTree()
        {
            using(var form = new Form()) {
                var button1 = new Button();
                var button2 = new Button();

                form.Controls.Add(button1);
                form.SetDataContext("test");
                form.Controls.Add(button2);

                button1.SetBinding("Text", new Binding());
                Assert.That(button1.Text, Is.EqualTo("test"));
                Assert.That(button1.HasLocalDataContext(), Is.False);

                button2.SetBinding("Text", new Binding());
                Assert.That(button2.Text, Is.EqualTo("test"));
                Assert.That(button2.HasLocalDataContext(), Is.False);

                form.SetDataContext("test2");
                Assert.That(button1.Text, Is.EqualTo("test2"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.Text, Is.EqualTo("test2"));
                Assert.That(button2.HasLocalDataContext(), Is.False);

                button1.SetDataContext("button1");
                Assert.That(button1.Text, Is.EqualTo("button1"));
                Assert.That(button1.HasLocalDataContext(), Is.True);
                button2.SetDataContext(null);
                Assert.That(button2.Text, Is.EqualTo(string.Empty));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                button1.ClearDataContext();
                Assert.That(button1.Text, Is.EqualTo("test2"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                button2.ClearDataContext();
                Assert.That(button2.Text, Is.EqualTo("test2"));
                Assert.That(button2.HasLocalDataContext(), Is.False);

                form.ClearDataContext();
                Assert.That(button1.Text, Is.EqualTo(string.Empty));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.Text, Is.EqualTo(string.Empty));
                Assert.That(button2.HasLocalDataContext(), Is.False);

                button1.SetDataContext("button1");
                Assert.That(button1.Text, Is.EqualTo("button1"));
                Assert.That(button1.HasLocalDataContext(), Is.True);

                form.SetDataContext("test");
                Assert.That(button1.Text, Is.EqualTo("button1"));
                Assert.That(button1.HasLocalDataContext(), Is.True);
                Assert.That(button2.Text, Is.EqualTo("test"));
                Assert.That(button2.HasLocalDataContext(), Is.False);

                form.Controls.Clear();
                Assert.That(button1.Text, Is.EqualTo("button1"));
                Assert.That(button2.Text, Is.EqualTo(string.Empty));
            }
        }
開發者ID:VitalyTVA,項目名稱:WinMVVM,代碼行數:59,代碼來源:BindingOperationsTests.cs


注:本文中的System.Windows.Forms.Form.ClearDataContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。