From 4729cbfdab60c3cd27694e2703e029d6b33642b0 Mon Sep 17 00:00:00 2001 From: ZX Date: Tue, 16 Apr 2019 16:29:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Null2VisibilityConverter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit value是null的时候隐藏,不为null显示 --- HandyControl/HandyControl.csproj | 1 + HandyControl/Themes/Basic/Converters.xaml | 1 + .../Converter/Null2VisibilityConverter.cs | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 HandyControl/Tools/Converter/Null2VisibilityConverter.cs diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj index df53b761..f6c8d4ef 100644 --- a/HandyControl/HandyControl.csproj +++ b/HandyControl/HandyControl.csproj @@ -156,6 +156,7 @@ + diff --git a/HandyControl/Themes/Basic/Converters.xaml b/HandyControl/Themes/Basic/Converters.xaml index 8a4d418f..1246361f 100644 --- a/HandyControl/Themes/Basic/Converters.xaml +++ b/HandyControl/Themes/Basic/Converters.xaml @@ -15,5 +15,6 @@ + \ No newline at end of file diff --git a/HandyControl/Tools/Converter/Null2VisibilityConverter.cs b/HandyControl/Tools/Converter/Null2VisibilityConverter.cs new file mode 100644 index 00000000..d1edc482 --- /dev/null +++ b/HandyControl/Tools/Converter/Null2VisibilityConverter.cs @@ -0,0 +1,20 @@ +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace HandyControl.Tools.Converter +{ + public class Null2VisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value == null ? Visibility.Collapsed : Visibility.Visible; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +}