简单实现变量的历史记录功能
This commit is contained in:
33
ValueConverts/NullableBooleanConverter.cs
Normal file
33
ValueConverts/NullableBooleanConverter.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace PMSWPF.ValueConverts
|
||||
{
|
||||
public class NullableBooleanConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool b && parameter is string paramString)
|
||||
{
|
||||
if (bool.TryParse(paramString, out bool paramBool))
|
||||
{
|
||||
return b == paramBool;
|
||||
}
|
||||
}
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool b && b && parameter is string paramString)
|
||||
{
|
||||
if (bool.TryParse(paramString, out bool paramBool))
|
||||
{
|
||||
return paramBool;
|
||||
}
|
||||
}
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user