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


C# Button.ClearBinding方法代碼示例

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


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

示例1: BindAttachedProperty2

        public void BindAttachedProperty2()
        {
            var viewModel = new TestViewModel();
            using(var button = new Button()) {
                button.SetValue(TextProperty, "button1");
                button.SetDataContext(viewModel);
                button.SetBinding(() => new Button().Text, new Binding(() => new TestViewModel().StringProperty2));
                button.SetBinding(TextProperty, new Binding(() => new TestViewModel().StringProperty));
                Assert.That(button.GetValue(TextProperty), Is.EqualTo(null));
                Assert.That(button.Text, Is.EqualTo(string.Empty));

                viewModel.StringProperty = "test";
                Assert.That(button.GetValue(TextProperty), Is.EqualTo("test"));
                Assert.That(button.Text, Is.EqualTo(string.Empty));

                viewModel.StringProperty2 = "test2";
                Assert.That(button.GetValue(TextProperty), Is.EqualTo("test"));
                Assert.That(button.Text, Is.EqualTo("test2"));

                button.ClearBinding(TextProperty);
                Assert.That(button.GetValue(TextProperty), Is.Null);
            }
        }
開發者ID:VitalyTVA,項目名稱:WinMVVM,代碼行數:23,代碼來源:BindingOperationsTests.cs

示例2: TwoWayBindingForAttachedProperty

        public void TwoWayBindingForAttachedProperty()
        {
            var viewModel = new TestViewModel() { };
            using(var button = new Button()) {
                button.SetDataContext(viewModel);

                PropertyEntry<object> entry = CommandProvider.CommandParameterProperty.GetPropertyEntry(button);

                Assert.That(entry.ChangedSubscribeCount, Is.EqualTo(0));
                button.SetBinding(CommandProvider.CommandParameterProperty, new Binding(() => viewModel.StringProperty, BindingMode.TwoWay));
                Assert.That(entry.ChangedSubscribeCount, Is.EqualTo(1));

                Assert.That(button.GetCommandParameter(), Is.Null);
                button.SetCommandParameter("test");
                Assert.That(viewModel.StringProperty, Is.EqualTo("test"));

                button.ClearBinding(CommandProvider.CommandParameterProperty);
                Assert.That(entry.ChangedSubscribeCount, Is.EqualTo(0));
                Assert.That(viewModel.StringProperty, Is.EqualTo("test"));
                Assert.That(button.GetCommandParameter(), Is.Null);

                viewModel.StringProperty = "test2";
                Assert.That(button.GetCommandParameter(), Is.Null);

                button.SetCommandParameter("test3");
            }
        }
開發者ID:VitalyTVA,項目名稱:WinMVVM,代碼行數:27,代碼來源:BindingOperationsTests.cs

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

示例4: SetBindingWithLambdaExpression

        public void SetBindingWithLambdaExpression()
        {
            using(var button = new Button()) {
                button.SetBinding(() => button.Text, new Binding());
                button.SetDataContext("test");
                Assert.That(button.Text, Is.EqualTo("test"));

                button.ClearBinding(() => button.Text);
                Assert.That(button.Text, Is.EqualTo(string.Empty));
            }
        }
開發者ID:VitalyTVA,項目名稱:WinMVVM,代碼行數:11,代碼來源:BindingOperationsTests.cs

示例5: IsBoundProperty

 public void IsBoundProperty()
 {
     using(var button = new Button()) {
         button.SetBinding("Text", new Binding());
         Assert.That(BindingOperations.IsBoundProperty(button, TypeDescriptor.GetProperties(button)["Text"]), Is.True);
         button.ClearBinding("Text");
         Assert.That(BindingOperations.IsBoundProperty(button, TypeDescriptor.GetProperties(button)["Text"]), Is.False);
     }
 }
開發者ID:VitalyTVA,項目名稱:WinMVVM,代碼行數:9,代碼來源:BindingOperationsTests.cs

示例6: BindingWithPath

        public void BindingWithPath()
        {
            var viewModel = new TestViewModel() { StringProperty = "test", StringProperty2 = "StringProperty2" };
            using(var button = new Button()) {
                button.SetDataContext(viewModel);
                button.SetBinding(() => button.Text, new Binding("StringProperty"));

                Assert.That(button.Text, Is.EqualTo("test"));
                viewModel.StringProperty = "test2";
                Assert.That(button.Text, Is.EqualTo("test2"));

                button.ClearBinding(() => button.Text);
                Assert.That(button.Text, Is.EqualTo(string.Empty));

                button.SetBinding(() => button.Text, new Binding("StringProperty"));
                Assert.That(button.Text, Is.EqualTo("test2"));
                button.SetBinding(() => button.Text, new Binding("StringProperty2"));
                Assert.That(button.Text, Is.EqualTo("StringProperty2"));

                viewModel = new TestViewModel() { StringProperty2 = "StringProperty2_", NestedViewModel = new NestedTestViewModel() { NestedStringProperty = "NestedStringProperty" } };
                button.SetDataContext(viewModel);
                Assert.That(button.Text, Is.EqualTo("StringProperty2_"));

                button.SetBinding(() => button.Text, new Binding("NestedViewModel.NestedStringProperty"));
                Assert.That(button.Text, Is.EqualTo("NestedStringProperty"));
                viewModel.NestedViewModel.NestedStringProperty = "NestedStringProperty2";
                Assert.That(button.Text, Is.EqualTo("NestedStringProperty2"));
                viewModel.NestedViewModel = new NestedTestViewModel() { NestedStringProperty = "NestedStringProperty3" };
                Assert.That(button.Text, Is.EqualTo("NestedStringProperty3"));
                viewModel.NestedViewModel = null;
                Assert.That(button.Text, Is.EqualTo(string.Empty));
            }
        }
開發者ID:VitalyTVA,項目名稱:WinMVVM,代碼行數:33,代碼來源:BindingOperationsTests.cs


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