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


C# Button.HasLocalDataContext方法代码示例

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


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

示例1: ClearDataContextWhenThereIsNoInheritedValueFromParent

 public void ClearDataContextWhenThereIsNoInheritedValueFromParent()
 {
     using(var form = new Form()) {
         var button1 = new Button();
         button1.SetDataContext("button3");
         form.Controls.Add(button1);
         button1.ClearDataContext();
         Assert.That(button1.GetDataContext(), Is.Null);
         Assert.That(button1.HasLocalDataContext(), Is.False);
         Assert.That(form.HasLocalDataContext(), Is.False);
     }
 }
开发者ID:VitalyTVA,项目名称:WinMVVM,代码行数:12,代码来源:DataContextProviderTests.cs

示例2: 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

示例3: InheritDataContextFromParent

        public void InheritDataContextFromParent()
        {
            using(var form = new Form()) {
                var button1 = new Button();
                var button2 = new Button();
                var button3 = new Button();
                button3.SetDataContext("button3");
                form.Controls.Add(button1);
                form.SetDataContext("test");
                form.Controls.Add(button2);
                form.Controls.Add(button3);
                Assert.That(button1.GetDataContext(), Is.EqualTo("test"));
                Assert.That(button2.GetDataContext(), Is.EqualTo("test"));
                Assert.That(button3.GetDataContext(), Is.EqualTo("button3"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.HasLocalDataContext(), Is.False);
                Assert.That(button3.HasLocalDataContext(), Is.True);

                button1.SetDataContext("button1");
                Assert.That(button1.GetDataContext(), Is.EqualTo("button1"));
                button2.SetDataContext(null);
                Assert.That(button2.GetDataContext(), Is.Null);
                Assert.That(button1.HasLocalDataContext(), Is.True);
                Assert.That(button2.HasLocalDataContext(), Is.True);

                button3.ClearDataContext();
                Assert.That(button3.GetDataContext(), Is.EqualTo("test"));
                Assert.That(button3.HasLocalDataContext(), Is.False);
               }
        }
开发者ID:VitalyTVA,项目名称:WinMVVM,代码行数:30,代码来源:DataContextProviderTests.cs

示例4: SetAndGetDataContextForControl

        public void SetAndGetDataContextForControl()
        {
            using(var button1 = new Button()) {
                Assert.That(button1.GetDataContext(), Is.Null);
                Assert.That(button1.HasLocalDataContext(), Is.False);
                button1.SetDataContext("test");
                Assert.That(button1.GetDataContext(), Is.EqualTo("test"));
                Assert.That(button1.HasLocalDataContext(), Is.True);

                button1.ClearDataContext();
                Assert.That(button1.GetDataContext(), Is.Null);
                Assert.That(button1.HasLocalDataContext(), Is.False);
            }

            using(var button2 = new Button()) {
                Assert.That(button2.GetDataContext(), Is.Null);
                button2.SetDataContext(13);
                Assert.That(button2.GetDataContext(), Is.EqualTo(13));
            }

            using(var button3 = new Button()) {
                button3.ClearDataContext();
                Assert.That(button3.GetDataContext(), Is.Null);
                Assert.That(button3.HasLocalDataContext(), Is.False);
            }
        }
开发者ID:VitalyTVA,项目名称:WinMVVM,代码行数:26,代码来源:DataContextProviderTests.cs

示例5: 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);
            }
        }
开发者ID:VitalyTVA,项目名称:WinMVVM,代码行数:20,代码来源:DataContextProviderTests.cs

示例6: 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

示例7: SetSimpleBindingBeforeSetDataContext

        public void SetSimpleBindingBeforeSetDataContext()
        {
            using(var button = new Button()) {
                button.SetBinding("Text", new Binding());
                Assert.That(button.HasLocalDataContext(), Is.False);

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

                button.SetDataContext("test2");
                Assert.That(button.Text, Is.EqualTo("test2"));

                button.ClearDataContext();
                Assert.That(button.Text, Is.EqualTo(string.Empty));

                button.SetDataContext("test3");
                Assert.That(button.Text, Is.EqualTo("test3"));

                button.ClearBinding("Text");
                button.ClearBinding("Tag");
                Assert.That(button.Text, Is.EqualTo(string.Empty));
                Assert.That(button.Tag, Is.Null);
                button.SetDataContext("test4");
                Assert.That(button.Text, Is.EqualTo(string.Empty));
            }
        }
开发者ID:VitalyTVA,项目名称:WinMVVM,代码行数:27,代码来源:BindingOperationsTests.cs

示例8: 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

示例9: InheritedDataContextBinding_BindBeforeAddToTree

        public void InheritedDataContextBinding_BindBeforeAddToTree()
        {
            using(var form = new Form()) {
                var button1 = new Button();
                var button2 = new Button();
                button1.SetBinding("Text", new Binding());
                button2.SetBinding("Text", new Binding());

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

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

                Assert.That(button2.Text, Is.EqualTo("test"));
                Assert.That(button2.HasLocalDataContext(), Is.False);
            }
        }
开发者ID:VitalyTVA,项目名称:WinMVVM,代码行数:19,代码来源:BindingOperationsTests.cs

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