mirror of
https://github.com/VitalickS/BrightSharp.Toolkit.git
synced 2026-03-21 02:21:15 +00:00
IntToValue Universal Converter
No toxic color DevLab Normal Brush
This commit is contained in:
@@ -34,6 +34,42 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</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>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
@@ -60,6 +96,7 @@
|
|||||||
<Compile Include="Commands\AsyncCommand.cs" />
|
<Compile Include="Commands\AsyncCommand.cs" />
|
||||||
<Compile Include="Commands\RelayCommand.cs" />
|
<Compile Include="Commands\RelayCommand.cs" />
|
||||||
<Compile Include="Controls\PropertyGrid.cs" />
|
<Compile Include="Controls\PropertyGrid.cs" />
|
||||||
|
<Compile Include="Converters\IntToValueConverter.cs" />
|
||||||
<Compile Include="Converters\InverseBooleanToVisibilityConverter.cs" />
|
<Compile Include="Converters\InverseBooleanToVisibilityConverter.cs" />
|
||||||
<Compile Include="Diagrams\Adorners\ResizeRotateAdorner.cs" />
|
<Compile Include="Diagrams\Adorners\ResizeRotateAdorner.cs" />
|
||||||
<Compile Include="Diagrams\Adorners\ResizeRotateChrome.cs" />
|
<Compile Include="Diagrams\Adorners\ResizeRotateChrome.cs" />
|
||||||
|
|||||||
60
BrightSharp/Converters/IntToValueConverter.cs
Normal file
60
BrightSharp/Converters/IntToValueConverter.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<Color x:Key="ValidationErrorColor">Red</Color>
|
<Color x:Key="ValidationErrorColor">Red</Color>
|
||||||
|
|
||||||
<SolidColorBrush x:Key="NormalBrush" Color="#FFDFE1EF" />
|
<SolidColorBrush x:Key="NormalBrush" Color="#FFEDEFFF" />
|
||||||
<SolidColorBrush x:Key="VerticalNormalBrush" Color="#FFDFE1EF" />
|
<SolidColorBrush x:Key="VerticalNormalBrush" Color="#FFDFE1EF" />
|
||||||
|
|
||||||
<LinearGradientBrush x:Key="ProgressBarIndeterminateRootBrush" EndPoint="0.5,1" StartPoint="0.5,0">
|
<LinearGradientBrush x:Key="ProgressBarIndeterminateRootBrush" EndPoint="0.5,1" StartPoint="0.5,0">
|
||||||
|
|||||||
Reference in New Issue
Block a user