public void when_Hidden_is_passed_then_false_is_returned() { var converter = new BooleanToVisibilityConverter(); var result = converter.ConvertBack(Visibility.Hidden, null, null, null); Assert.That(result, Is.False); }
public void ThrowsForSameVisibilityProperties() { var converter = new BooleanToVisibilityConverter(Visibility.Visible, Visibility.Visible); Assert.Throws <InvalidOperationException>(() => converter.ConvertBack(Visibility.Visible, null, CultureInfo.CurrentCulture)); }
public void when_Visible_is_passed_then_true_is_returned() { var converter = new BooleanToVisibilityConverter(); var result = converter.ConvertBack(Visibility.Visible, null, null, null); Assert.That(result, Is.True); }
public void when_false_is_passed_then_Collapsed_is_returned() { var converter = new BooleanToVisibilityConverter(); var result = converter.Convert(false, null, null, null); Assert.That(result, Is.EqualTo(Visibility.Collapsed)); }
public void BooleanToVisibilityConverter() { var converter = new BooleanToVisibilityConverter(); Assert.AreEqual(Visibility.Visible, converter.Convert(true, typeof(Visibility), null, null)); Assert.AreEqual(Visibility.Collapsed, converter.Convert(false, typeof(Visibility), null, null)); Assert.AreEqual(Visibility.Visible, converter.Convert(new Nullable <bool>(true), typeof(Visibility), null, null)); Assert.AreEqual(Visibility.Collapsed, converter.Convert(new Nullable <bool>(false), typeof(Visibility), null, null)); Assert.AreEqual(Visibility.Collapsed, converter.Convert(new Nullable <bool>(), typeof(Visibility), null, null)); Assert.AreEqual(Visibility.Collapsed, converter.Convert(null, typeof(Visibility), null, null)); Assert.AreEqual(Visibility.Collapsed, converter.Convert("test", typeof(Visibility), null, null)); Assert.AreEqual(true, converter.ConvertBack(Visibility.Visible, typeof(bool), null, null)); Assert.AreEqual(false, converter.ConvertBack(Visibility.Collapsed, typeof(bool), null, null)); Assert.AreEqual(false, converter.ConvertBack("test", typeof(bool), null, null)); Assert.AreEqual(new bool?(true), converter.ConvertBack(Visibility.Visible, typeof(bool?), null, null)); Assert.AreEqual(new bool?(false), converter.ConvertBack(Visibility.Collapsed, typeof(bool?), null, null)); Assert.AreEqual(false, converter.ConvertBack(Visibility.Hidden, typeof(bool), null, null)); Assert.AreEqual(new bool?(false), converter.ConvertBack(Visibility.Hidden, typeof(bool?), null, null)); converter.Inverse = true; Assert.AreEqual(Visibility.Collapsed, converter.Convert(true, typeof(Visibility), null, null)); Assert.AreEqual(Visibility.Visible, converter.Convert(false, typeof(Visibility), null, null)); Assert.AreEqual(false, converter.ConvertBack(Visibility.Visible, typeof(bool), null, null)); Assert.AreEqual(true, converter.ConvertBack(Visibility.Collapsed, typeof(bool), null, null)); Assert.AreEqual(true, converter.ConvertBack(Visibility.Hidden, typeof(bool), null, null)); converter.Inverse = false; converter.HiddenInsteadOfCollapsed = true; Assert.AreEqual(Visibility.Visible, converter.Convert(true, typeof(Visibility), null, null)); Assert.AreEqual(true, converter.ConvertBack(Visibility.Visible, typeof(bool), null, null)); Assert.AreEqual(false, converter.ConvertBack(Visibility.Collapsed, typeof(bool), null, null)); Assert.AreEqual(Visibility.Hidden, converter.Convert(false, typeof(Visibility), null, null)); Assert.AreEqual(false, converter.ConvertBack(Visibility.Hidden, typeof(bool), null, null)); }
public void ThrowsForUnknownVisibility() { var converter = new BooleanToVisibilityConverter(Visibility.Visible, Visibility.Collapsed); Assert.Throws <InvalidOperationException>(() => converter.ConvertBack(Visibility.Hidden, null, CultureInfo.CurrentCulture)); }
public void ShouldConvertBackNullValue() { var converter = new BooleanToVisibilityConverter(); var value = (bool)converter.ConvertBack(null, null, null, null); Assert.AreEqual(false, value); }
public void Invalid_value_and_target_type() { var converter = new BooleanToVisibilityConverter(); Assert.ThrowsException <InvalidOperationException>(() => converter.Convert(1, typeof(string), null, null)); }
public AIView() { InitializeComponent(); this.WhenActivated(d => { this.OneWayBind(ViewModel, vm => vm.PlayerState.FirstCard, v => v.xFirstCard.Content).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.PlayerState.SecondCard, v => v.xSecondCard.Content).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.PlayerState.Cash, v => v.xCash.Text, cash => cash.ToString()).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.PlayerState.Name, v => v.xPlayerName.Text); this.OneWayBind(ViewModel, vm => vm.PlayerState.IsDealer, v => v.xIsDealer.Visibility, x => { var conv = new BooleanToVisibilityConverter(); return((Visibility)conv.Convert(x, typeof(Visibility), null, System.Globalization.CultureInfo.CurrentCulture)); }).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.PlayerState.IsSmallBlind, v => v.xIsSmallBlind.Visibility, x => { var conv = new BooleanToVisibilityConverter(); return((Visibility)conv.Convert(x, typeof(Visibility), null, System.Globalization.CultureInfo.CurrentCulture)); }).DisposeWith(d); this.OneWayBind(ViewModel, vm => vm.PlayerState.IsBigBlind, v => v.xIsBigBlind.Visibility, x => { var conv = new BooleanToVisibilityConverter(); return((Visibility)conv.Convert(x, typeof(Visibility), null, System.Globalization.CultureInfo.CurrentCulture)); }).DisposeWith(d); }); }
public void ConvertBackShouldThrowExceptionInvalidValue() { var converter = new BooleanToVisibilityConverter(Visibility.Collapsed, Visibility.Visible, Visibility.Visible); Action action = () => converter.ConvertBack(new object(), typeof(object), null, null); action.ShouldThrow(); }
private void Window_KeyDown(object sender, KeyEventArgs e) { BooleanToVisibilityConverter visibilityConverter = new BooleanToVisibilityConverter(); if (e.Key == Key.Escape) { if ((bool)visibilityConverter.ConvertBack(grGame.Visibility, null, null, null) && !(bool)visibilityConverter.ConvertBack(dlgDefeat.Visibility, null, null, null) && !(bool)visibilityConverter.ConvertBack(dlgVictory.Visibility, null, null, null) && !(bool)visibilityConverter.ConvertBack(grStats.Visibility, null, null, null) && GameModel.isLoadTimerEnd) { GameModel.Pause = !GameModel.Pause; } } if (e.Key == Key.R) { if (!GameModel.isModelReady) { return; } Rifle.Reload(Scope.isZoomIn, Rifle.isBoltAnimation || Rifle.isShootAnimation || Rifle.isReloadAnimation || Scope.isScopeAnimation); } if (e.Key == Key.S) { Soundtrack.NextTrack(); } }
public void BooleanToVisibilityConverterShouldWork() { var converter = new BooleanToVisibilityConverter(); Assert.AreEqual(Visibility.Visible, (Visibility)converter.Convert(true, typeof(bool), null, CultureInfo.CurrentCulture)); Assert.AreEqual(Visibility.Collapsed, (Visibility)converter.Convert(false, typeof(bool), null, CultureInfo.CurrentCulture)); Assert.AreEqual(Visibility.Collapsed, (Visibility)converter.Convert(null, typeof(bool), null, CultureInfo.CurrentCulture)); }
public void ShouldConvertBackCollapsedToFalse() { var converter = new BooleanToVisibilityConverter(); var value = (bool)converter.ConvertBack(Visibility.Collapsed, null, null, null); Assert.AreEqual(false, value); }
public void ShouldConvertBackVisibleToTrue() { var converter = new BooleanToVisibilityConverter(); var value = (bool)converter.ConvertBack(Visibility.Visible, null, null, null); Assert.AreEqual(true, value); }
public void ShouldConvertTrueToVisible() { var converter = new BooleanToVisibilityConverter(); var visibility = (Visibility)converter.Convert(true, null, null, null); Assert.AreEqual(Visibility.Visible, visibility); }
public override object ProvideValue(IServiceProvider serviceProvider) { if (null == booleanToVisibilityConverter) booleanToVisibilityConverter = new BooleanToVisibilityConverter(); return booleanToVisibilityConverter; }
public void ShouldConvertFalseToCollapsed() { var converter = new BooleanToVisibilityConverter(); var visibility = (Visibility)converter.Convert(false, null, null, null); Assert.AreEqual(Visibility.Collapsed, visibility); }
public MainWindow() { InitializeComponent(); AttachConsole(-1); hiddenOrVisible = new BooleanToVisibilityConverter(); this.DataContext = new TankViewModel(); }
/// <summary> /// Hooks the buttons in the control template up to the dock commands. /// </summary> private void InitializeButtons() { var booleanToVisibilityConverter = new BooleanToVisibilityConverter(); if (_autoHideButton != null) { _autoHideButton.Command = DockCommands.AutoHide; _autoHideButton.CommandTarget = this; _autoHideButton.SetBinding(VisibilityProperty, new Binding("IsEnabled") { Source = _autoHideButton, Converter = booleanToVisibilityConverter }); } if (_dockButton != null) { _dockButton.Command = DockCommands.Dock; _dockButton.CommandTarget = this; _dockButton.SetBinding(VisibilityProperty, new Binding("IsEnabled") { Source = _dockButton, Converter = booleanToVisibilityConverter }); } if (_closeButton != null) { _closeButton.Command = ApplicationCommands.Close; _closeButton.CommandTarget = this; _closeButton.SetBinding(VisibilityProperty, new Binding("IsEnabled") { Source = _closeButton, Converter = booleanToVisibilityConverter }); } if (_windowListButton != null) { _windowListButton.Command = DockCommands.ShowMenu; _windowListButton.CommandTarget = this; _windowListButton.SetBinding(VisibilityProperty, new Binding("IsEnabled") { Source = _windowListButton, Converter = booleanToVisibilityConverter }); } }
public void convert_back_returns_unset_value_if_value_is_not_a_visibility_enumeration_member() { var converter = new BooleanToVisibilityConverter(); Assert.Equal(DependencyProperty.UnsetValue, converter.ConvertBack(null, null, null, null)); Assert.Equal(DependencyProperty.UnsetValue, converter.ConvertBack("Visible", null, null, null)); Assert.Equal(DependencyProperty.UnsetValue, converter.ConvertBack(1, null, null, null)); }
public void ShouldConvertNullValue() { var converter = new BooleanToVisibilityConverter(); var result = converter.Convert(null, null, null, null); Assert.IsNull(result); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var converter = new BooleanToVisibilityConverter(); return((Visibility)converter.Convert(value, targetType, null, culture) == Visibility.Visible ? "tak" : "nie"); }
public void ShouldConvertNullNullableBoolToHidden() { var converter = new BooleanToVisibilityConverter(); var visibility = converter.Convert((bool?)null, null, null, null); Assert.Equal(Visibility.Hidden, visibility); }
public void ShouldConvertFalseBoolToHidden() { var converter = new BooleanToVisibilityConverter(); var visibility = converter.Convert(false, null, null, null); Assert.Equal(Visibility.Hidden, visibility); }
public void BooleanToVisibilityConverter_EnsureDefaultForTrueIsVisible() { var converter = new BooleanToVisibilityConverter(); Visibility visibility = (Visibility)converter.Convert(true, null, null, null); Assert.AreEqual(Visibility.Visible, visibility); }
public void BooleanToVisibilityConverter_EnsureDefaultForFalseIsCollapsed() { var converter = new BooleanToVisibilityConverter(); Visibility visibility = (Visibility)converter.Convert(false, null, null, null); Assert.AreEqual(Visibility.Collapsed, visibility); }
public void ShouldConvertTrueNullableBoolToVisible() { var converter = new BooleanToVisibilityConverter(); var visibility = converter.Convert((bool?)true, null, null, null); Assert.Equal(Visibility.Visible, visibility); }
public void when_nullable_true_is_passed_then_Visible_is_returned() { var converter = new BooleanToVisibilityConverter(); var value = (bool?)true; var result = converter.Convert(value, null, null, null); Assert.That(result, Is.EqualTo(Visibility.Visible)); }
public void Test_ConvertBack_UndefinedValue() { var target = new BooleanToVisibilityConverter(); target.ReverseLogic = false; target.InvisibleToHidden = true; target.ConvertBack(unchecked ((Visibility)(-1)), null, null, null).Should().Be(DependencyProperty.UnsetValue); }
public void Test_Convert_NotExpectType() { var target = new BooleanToVisibilityConverter(); target.InvisibleToHidden = true; target.Convert(1, null, null, null).Should().Be(DependencyProperty.UnsetValue); target.Convert("0", null, null, null).Should().Be(DependencyProperty.UnsetValue); }
public void convert_returns_hidden_if_value_is_false_and_use_hidden_is_true() { var converter = new BooleanToVisibilityConverter { UseHidden = true }; Assert.Equal(Visibility.Hidden, converter.Convert(false, null, null, null)); }
public void convert_returns_visible_if_value_is_false_and_is_reversed_is_true() { var converter = new BooleanToVisibilityConverter { IsReversed = true }; Assert.Equal(Visibility.Visible, converter.Convert(false, null, null, null)); }
public void ConvertBackTest() { const Visibility trueValue = Visibility.Collapsed; const Visibility falseValue = Visibility.Visible; var converter = new BooleanToVisibilityConverter(Visibility.Collapsed, Visibility.Visible, Visibility.Visible); converter.ConvertBack(trueValue, typeof(bool), null, null).ShouldEqual(true); converter.ConvertBack(falseValue, typeof(bool), null, null).ShouldEqual(false); }
public void convert_returns_collapsed_if_value_is_true_and_is_reversed_is_true() { var converter = new BooleanToVisibilityConverter { IsReversed = true }; Assert.Equal(Visibility.Collapsed, converter.Convert(true, null, null, null)); }
public void Test_Convert_NormalLogic_InvisibleCollapse() { var target = new BooleanToVisibilityConverter(); target.ReverseLogic = false; target.InvisibleToHidden = false; target.Convert(true, null, null, null).Should().Be(Visibility.Visible); target.Convert(false, null, null, null).Should().Be(Visibility.Collapsed); }
public void Test_Convert_ReverseLogic_InvisibleHidden() { var target = new BooleanToVisibilityConverter(); target.ReverseLogic = true; target.InvisibleToHidden = true; target.Convert(true, null, null, null).Should().Be(Visibility.Hidden); target.Convert(false, null, null, null).Should().Be(Visibility.Visible); }
public void ConvertsBackCorrect( Visibility input, BooleanToVisibilityConverter.BooleanToVisibilityMapping parameter, bool expectedResult) { var converter = new BooleanToVisibilityConverter(); var result = converter.ConvertBack(input, parameter, CultureInfo.InvariantCulture); Assert.Equal(expectedResult, result); }
public void ConvertBackThrowsCorrect( Visibility input, BooleanToVisibilityConverter.BooleanToVisibilityMapping parameter) { var converter = new BooleanToVisibilityConverter(); Assert.Throws<ArgumentOutOfRangeException>( () => converter.ConvertBack( input, parameter, CultureInfo.InvariantCulture)); }
public void Test () { BooleanToVisibilityConverter c = new BooleanToVisibilityConverter (); Assert.AreEqual (c.Convert (true, null, null, null), Visibility.Visible, "true"); Assert.AreEqual (c.Convert (false, null, null, null), Visibility.Collapsed, "false"); Assert.AreEqual (c.Convert (null, null, null, null), Visibility.Collapsed, "null"); Assert.AreEqual (c.Convert ((bool?)true, null, null, null), Visibility.Visible, "(bool?)true"); Assert.AreEqual (c.Convert ((bool?)false, null, null, null), Visibility.Collapsed, "(bool?)false"); Assert.AreEqual (c.Convert ((bool?)null, null, null, null), Visibility.Collapsed, "(bool?)null"); Assert.AreEqual (c.Convert (string.Empty, null, null, null), Visibility.Collapsed, "string.Empty"); Assert.IsTrue ((bool)c.ConvertBack (Visibility.Visible, null, null, null), "Visibility.Visible"); Assert.IsFalse ((bool)c.ConvertBack (Visibility.Hidden, null, null, null), "Visibility.Hidden"); Assert.IsFalse ((bool)c.ConvertBack (Visibility.Collapsed, null, null, null), "Visibility.Collapsed"); Assert.IsFalse ((bool)c.ConvertBack (null, null, null, null), "null"); }
/// <summary> /// When the page is loaded, retrieve the persisted column layout /// This is a pretty grubby way of doing things but I couldn't think /// of anything better :/ /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Page_Loaded(object sender, RoutedEventArgs e) { //this event will fire not only when is first shown, but every time its shown // eg when switching between tabs. Not sure why if (_loaded) return; //fetch the layout from settings string xaml = Properties.Settings.Default.SearchColumns; if (!String.IsNullOrEmpty(xaml)) { GridViewColumnCollection savedCols = XamlReader.Parse(xaml) as GridViewColumnCollection; GridViewColumnCollection gridViewCols = ((GridView)listView1.View).Columns; //we can't share GridViewColumns between collections, nor can we //remove one during a foreach, so we have to copy them to a list, //then add them to the collection. List<GridViewColumn> tempCols = new List<GridViewColumn>(); foreach (GridViewColumn col in savedCols) { tempCols.Add(col); } gridViewCols.Clear(); savedCols.Clear(); //TODO: we should be using the existing converter resource rather than making a new one BooleanToVisibilityConverter boolToVisCon = new BooleanToVisibilityConverter(); foreach (GridViewColumn col in tempCols) { //add the templates, bindings, and set the visible states as these aren't persisted col.HeaderTemplate = listView1.TryFindResource("HeaderTemplateSortNon") as DataTemplate; GridViewColumnHeader gvch = col.Header as GridViewColumnHeader; MenuItem mnu = this.FindName("mnuCol" + gvch.Content.ToString()) as MenuItem; mnu.IsChecked = (gvch.Visibility == System.Windows.Visibility.Visible); Binding b = new Binding("IsChecked"); b.ElementName = "mnuCol" + gvch.Content.ToString(); b.Converter = boolToVisCon; gvch.SetBinding(UIElement.VisibilityProperty, b); gridViewCols.Add(col); } } _loaded = true; }
public void convert_returns_visible_if_value_is_true() { var converter = new BooleanToVisibilityConverter(); Assert.Equal(Visibility.Visible, converter.Convert(true, null, null, null)); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { var dts = new DataTemplates(); if (item is ImageAction) { var ia = item as ImageAction; if (ia.IsEditMode) { var defaultDt = (dts.FindResource("default") as DataTemplate); FrameworkElementFactory factory = new FrameworkElementFactory(typeof(ContentPresenter)); factory.SetValue(ContentPresenter.ContentTemplateProperty, defaultDt); var conv = new BooleanToVisibilityConverter(); var mainPanel = new FrameworkElementFactory(typeof(StackPanel)); mainPanel.AppendChild(factory); var sp = new FrameworkElementFactory(typeof(StackPanel)); sp.SetBinding(StackPanel.VisibilityProperty, new Binding("IsEditMode") { Converter = conv }); foreach (var prop in ia.GetType().GetProperties()) { object[] attrs = prop.GetCustomAttributes(true); if (attrs == null || attrs.Length == 0) continue; foreach (Attribute attr in attrs) { if (attr is SliderAttribute) { sp.AppendChild(GenerateLabel(prop)); var sl = attr as SliderAttribute; var slider = new FrameworkElementFactory(typeof(Slider)); slider.SetValue(Slider.MaximumProperty, sl.MaxVal); slider.SetValue(Slider.MinimumProperty, sl.MinVal); if (sl.IsIntegerType) { slider.SetValue(Slider.IsSnapToTickEnabledProperty, true); slider.SetValue(Slider.TickFrequencyProperty, sl.Increment); slider.SetValue(Slider.SmallChangeProperty, sl.Increment); } slider.SetValue(Slider.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); slider.SetValue(Slider.MarginProperty, new Thickness(5)); slider.SetBinding(Slider.ValueProperty, new Binding(prop.Name)); var tb = new FrameworkElementFactory(typeof(TextBlock)); tb.SetValue(TextBlock.PaddingProperty, new Thickness(5)); tb.SetBinding(TextBlock.TextProperty, new Binding(prop.Name) { StringFormat = sl.IsIntegerType ? "N1" : "N2" }); sp.AppendChild(tb); sp.AppendChild(slider); sp.AppendChild(new FrameworkElementFactory(typeof(Separator))); } if (attr is EnumAttribute) { sp.AppendChild(GenerateLabel(prop)); var en = attr as EnumAttribute; var combo = new FrameworkElementFactory(typeof(ComboBox)); combo.SetValue(ComboBox.ItemsSourceProperty, Enum.GetValues(en.EnumClass)); combo.SetValue(ComboBox.SelectedItemProperty, new Binding(prop.Name)); sp.AppendChild(combo); sp.AppendChild(new FrameworkElementFactory(typeof(Separator))); } if (attr is RGBColorAttribute) { sp.AppendChild(GenerateLabel(prop)); var rgb = attr as RGBColorAttribute; var cp = new FrameworkElementFactory(typeof(ColorCanvas)); cp.SetBinding(ColorCanvas.SelectedColorProperty, new Binding(prop.Name)); cp.SetValue(ColorCanvas.UsingAlphaChannelProperty, false); sp.AppendChild(cp); sp.AppendChild(new FrameworkElementFactory(typeof(Separator))); } } } //var dp = new FrameworkElementFactory(typeof(DockPanel)); //var applyBt = new FrameworkElementFactory(typeof(Button)); //applyBt.SetBinding(Button.IsEnabledProperty, new Binding("HasChanged") { Mode = BindingMode.TwoWay }); //applyBt.SetValue(DockPanel.DockProperty, Dock.Right); //applyBt.SetValue(Button.PaddingProperty, new Thickness(5)); //applyBt.SetBinding(Button.CommandProperty, new Binding("ApplyCommand") //{ // ElementName = "current", // Path = new PropertyPath("DataContext.ApplyCommand") //}); //applyBt.SetBinding(Button.CommandParameterProperty, new Binding()); //applyBt.SetValue(Button.ContentProperty, "Apply Changes"); //dp.AppendChild(applyBt); //sp.AppendChild(dp); mainPanel.AppendChild(sp); return new DataTemplate() { VisualTree = mainPanel }; } //Non edit mode return dts.FindResource("default") as DataTemplate; } return null; }
private static Visibility GetVisibility(bool boolean) { BooleanToVisibilityConverter converter = new BooleanToVisibilityConverter(); return (Visibility)converter.Convert(boolean, null, null, null); }
/// <summary> /// Modifies the target data before passing it to the source object. This method is called only in <see cref="F:System.Windows.Data.BindingMode.TwoWay" /> bindings. /// </summary> /// <param name="value">The target data being passed to the source.</param> /// <param name="targetType">The <see cref="T:System.Type" /> of data expected by the source object.</param> /// <param name="parameter">An optional parameter to be used in the converter logic.</param> /// <param name="culture">The culture of the conversion.</param> /// <returns>The value to be passed to the source object.</returns> public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var converter = new BooleanToVisibilityConverter(); converter.Invert = this.Invert; return converter.Convert(value, targetType, parameter, culture); }
public InverseBooleanToVisibilityConverter() { converter = new BooleanToVisibilityConverter(); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); FrameworkElement windowHeaderElement; if (Template.TryFindName(PartNameWindowHeader, this, out windowHeaderElement)) { _templatePartWindowHeader = windowHeaderElement; var chrome = WindowChrome.GetWindowChrome(this); Binding captionHeightBinding = new Binding(); captionHeightBinding.Source = windowHeaderElement; captionHeightBinding.Path = new PropertyPath(nameof(FrameworkElement.ActualHeight)); captionHeightBinding.Mode = BindingMode.OneWay; captionHeightBinding.NotifyOnSourceUpdated = true; BindingOperations.SetBinding(chrome, WindowChrome.CaptionHeightProperty, captionHeightBinding); } var visibilityConverter = new BooleanToVisibilityConverter(); if (Template.TryFindName(PartNameCloseButton, this, out _templatePartButtonClose)) { _templatePartButtonClose.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, true); _templatePartButtonClose.PreviewMouseLeftButtonUp += TemplatePartButtonCloseOnMouseUp; _templatePartButtonClose.SetBinding(VisibilityProperty, IsCloseButtonVisibleProperty, this, visibilityConverter); } if (Template.TryFindName(PartNameMinimizeButton, this, out _templatePartButtonMinimize)) { _templatePartButtonMinimize.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, true); _templatePartButtonMinimize.PreviewMouseLeftButtonUp += TemplatePartButtonMinimizeOnMouseUp; _templatePartButtonMinimize.SetBinding(VisibilityProperty, IsMinimizeButtonVisibleProperty, this, visibilityConverter); } if (Template.TryFindName(PartNameMaximizeButton, this, out _templatePartButtonMaximize)) { _templatePartButtonMaximize.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, true); _templatePartButtonMaximize.PreviewMouseLeftButtonUp += TemplatePartButtonMaximizeOnMouseUp; _templatePartButtonMaximize.SetBinding(VisibilityProperty, IsMaximizeButtonVisibleProperty, this, visibilityConverter); } if (Template.TryFindName(PartNameRestoreButton, this, out _templatePartButtonRestore)) { _templatePartButtonRestore.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, true); _templatePartButtonRestore.PreviewMouseLeftButtonUp += TemplatePartButtonRestoreOnMouseUp; _templatePartButtonRestore.SetBinding(VisibilityProperty, IsRestoreButtonVisibleProperty, this, visibilityConverter); } AdjustVisibilityToWindowState(); }
public void ctor_defaults_is_reversed_to_false() { var converter = new BooleanToVisibilityConverter(); Assert.False(converter.IsReversed); }
public void convert_automatically_converts_relevant_values_to_booleans() { var converter = new BooleanToVisibilityConverter(); Assert.Equal(Visibility.Collapsed, converter.Convert("false", null, null, null)); Assert.Equal(Visibility.Collapsed, converter.Convert("False", null, null, null)); Assert.Equal(Visibility.Collapsed, converter.Convert("FALSE", null, null, null)); Assert.Equal(Visibility.Collapsed, converter.Convert(0, null, null, null)); Assert.Equal(Visibility.Collapsed, converter.Convert(0d, null, null, null)); Assert.Equal(Visibility.Visible, converter.Convert("true", null, null, null)); Assert.Equal(Visibility.Visible, converter.Convert("True", null, null, null)); Assert.Equal(Visibility.Visible, converter.Convert("TRUE", null, null, null)); Assert.Equal(Visibility.Visible, converter.Convert(1, null, null, null)); Assert.Equal(Visibility.Visible, converter.Convert(1d, null, null, null)); }
private static bool GetBool(Visibility visibility) { BooleanToVisibilityConverter converter = new BooleanToVisibilityConverter(); return (bool)converter.ConvertBack(visibility, null, null, null); }
public void convert_back_returns_false_if_value_is_hidden() { var converter = new BooleanToVisibilityConverter(); Assert.Equal(false, converter.ConvertBack(Visibility.Hidden, null, null, null)); }
public void ctor_defaults_use_hidden_to_false() { var converter = new BooleanToVisibilityConverter(); Assert.False(converter.UseHidden); }
public void convert_back_returns_true_if_value_is_hidden_and_is_reversed_is_true() { var converter = new BooleanToVisibilityConverter { IsReversed = true }; Assert.Equal(true, converter.ConvertBack(Visibility.Hidden, null, null, null)); }
public void ctor_assigns_specified_use_hidden_value() { var converter = new BooleanToVisibilityConverter(false, true); Assert.True(converter.UseHidden); }
public void ctor_assigns_specified_is_reversed_value() { var converter = new BooleanToVisibilityConverter(true, false); Assert.True(converter.IsReversed); }
public void convert_returns_collapsed_if_value_is_false_and_use_hidden_is_false() { var converter = new BooleanToVisibilityConverter(); Assert.Equal(Visibility.Collapsed, converter.Convert(false, null, null, null)); }
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var c = new BooleanToVisibilityConverter(); return !(bool)c.ConvertBack(value, targetType, parameter, culture); }