IntToValue Universal Converter

No toxic color DevLab Normal Brush
This commit is contained in:
2019-04-27 21:21:48 +03:00
parent 77b83a61d8
commit 70aada3d59
3 changed files with 98 additions and 1 deletions

View File

@@ -34,6 +34,42 @@
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
@@ -60,6 +96,7 @@
<Compile Include="Commands\AsyncCommand.cs" />
<Compile Include="Commands\RelayCommand.cs" />
<Compile Include="Controls\PropertyGrid.cs" />
<Compile Include="Converters\IntToValueConverter.cs" />
<Compile Include="Converters\InverseBooleanToVisibilityConverter.cs" />
<Compile Include="Diagrams\Adorners\ResizeRotateAdorner.cs" />
<Compile Include="Diagrams\Adorners\ResizeRotateChrome.cs" />

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections;
using System.Globalization;
using System.Windows.Data;
namespace BrightSharp.Converters
{
public class IntToValueConverter : IValueConverter
{
public ulong? TrueValueInt { get; set; } = null;
public ulong? FalseValueInt { get; set; } = 0;
public object TrueValue { get; set; } = true;
public object FalseValue { get; set; } = false;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
value = false;
}
if (value is string valueStr)
{
value = valueStr.Length > 0;
}
if (value is bool valueBool)
{
value = valueBool ? 1 : 0;
}
if (value is ICollection valueCol)
{
value = valueCol.Count;
}
if (value is Enum en)
{
value = System.Convert.ToInt32(en);
}
if (ulong.TryParse(value.ToString(), out ulong valueLong))
{
// Exact match for false
if (FalseValueInt.HasValue && FalseValueInt == valueLong) return FalseValue;
// Exact match for true
if (TrueValueInt.HasValue && TrueValueInt == valueLong) return TrueValue;
// Any value for false
if (!FalseValueInt.HasValue) return FalseValue;
// Any value for true
if (!TrueValueInt.HasValue) return TrueValue;
}
return TrueValue;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// Convert with potential lose exact value match
return Equals(value, TrueValue) ? TrueValueInt : FalseValueInt;
}
}
}

View File

@@ -17,7 +17,7 @@
<Color x:Key="ValidationErrorColor">Red</Color>
<SolidColorBrush x:Key="NormalBrush" Color="#FFDFE1EF" />
<SolidColorBrush x:Key="NormalBrush" Color="#FFEDEFFF" />
<SolidColorBrush x:Key="VerticalNormalBrush" Color="#FFDFE1EF" />
<LinearGradientBrush x:Key="ProgressBarIndeterminateRootBrush" EndPoint="0.5,1" StartPoint="0.5,0">