From fbcc910f949296b5749bbad36fa3fcd503a0fd56 Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Mon, 22 Jul 2019 22:15:51 +0200 Subject: [PATCH] Handle null as a valid boolean value in BoolToVisibilityConverter. --- .../ValueConverters/Generic/BoolToVisibility.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Application/FileConverter/ValueConverters/Generic/BoolToVisibility.cs b/Application/FileConverter/ValueConverters/Generic/BoolToVisibility.cs index e278ef6..5a6d03f 100644 --- a/Application/FileConverter/ValueConverters/Generic/BoolToVisibility.cs +++ b/Application/FileConverter/ValueConverters/Generic/BoolToVisibility.cs @@ -10,11 +10,13 @@ namespace FileConverter.ValueConverters.Generic { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (!(value is bool)) + if (value != null && !(value is bool)) { throw new ArgumentException("The value must be a boolean."); } + bool booleanValue = (bool?) value ?? false; + string stringParameter = parameter as string; string trueResult = "Visible"; @@ -35,7 +37,6 @@ namespace FileConverter.ValueConverters.Generic } } - bool booleanValue = (bool)value; return booleanValue ? trueResult : falseResult; }