瀏覽代碼

#1798 Test for binding checkbox with three state.

MonkAlex 7 年之前
父節點
當前提交
e69f3c7f85
共有 1 個文件被更改,包括 26 次插入0 次删除
  1. 26 0
      tests/Avalonia.Controls.UnitTests/Primitives/ToggleButtonTests.cs

+ 26 - 0
tests/Avalonia.Controls.UnitTests/Primitives/ToggleButtonTests.cs

@@ -44,15 +44,41 @@ namespace Avalonia.Controls.Primitives.UnitTests
             Assert.False(toggleButton.IsChecked);
         }
 
+        [Fact]
+        public void ToggleButton_ThreeState_Checked_Binds_To_Nullable_Bool()
+        {
+            var threeStateButton = new ToggleButton();
+            var source = new Class1();
+
+            threeStateButton.DataContext = source;
+            threeStateButton.Bind(ToggleButton.IsCheckedProperty, new Binding(nameof(Class1.NullableFoo)));
+
+            source.NullableFoo = true;
+            Assert.True(threeStateButton.IsChecked);
+
+            source.NullableFoo = false;
+            Assert.False(threeStateButton.IsChecked);
+
+            source.NullableFoo = null;
+            Assert.Null(threeStateButton.IsChecked);
+        }
+
         private class Class1 : NotifyingBase
         {
             private bool _foo;
+            private bool? nullableFoo;
 
             public bool Foo
             {
                 get { return _foo; }
                 set { _foo = value; RaisePropertyChanged(); }
             }
+
+            public bool? NullableFoo
+            {
+                get { return nullableFoo; }
+                set { nullableFoo = value; RaisePropertyChanged(); }
+            }
         }
     }
 }