更新
This commit is contained in:
31
WPFDark/Controls/Converters/BoolInverseConverter.cs
Normal file
31
WPFDark/Controls/Converters/BoolInverseConverter.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WPFDark.Controls.Converters
|
||||
{
|
||||
public class BoolInverseConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is null)
|
||||
return Binding.DoNothing;
|
||||
|
||||
if (value is bool b)
|
||||
return b == false;
|
||||
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is null)
|
||||
return Binding.DoNothing;
|
||||
|
||||
if (value is bool b)
|
||||
return b == false;
|
||||
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
WPFDark/Controls/Converters/DoubleColorToBrushConverter.cs
Normal file
22
WPFDark/Controls/Converters/DoubleColorToBrushConverter.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WPFDark.Controls.Converters
|
||||
{
|
||||
public class DoubleColorToBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is DoubleColor item))
|
||||
return null!;
|
||||
|
||||
return Caches.GetSolidColorBrush(item.ByteColor);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
52
WPFDark/Controls/Converters/IndentToMarginConverter.cs
Normal file
52
WPFDark/Controls/Converters/IndentToMarginConverter.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using Jewelry.Collections;
|
||||
|
||||
using WPFDark.Internals;
|
||||
|
||||
namespace WPFDark.Controls.Converters
|
||||
{
|
||||
public class IndentToMarginConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var thickness = new Thickness(0);
|
||||
if (values is null)
|
||||
return thickness;
|
||||
|
||||
if (!(values[0] is TreeViewItem item))
|
||||
return thickness;
|
||||
|
||||
var length = 19.0;
|
||||
|
||||
if (values.Length == 2)
|
||||
if (values[1] is double v)
|
||||
length = v;
|
||||
|
||||
var k = length * item.GetDepth();
|
||||
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
if (k == 0)
|
||||
return thickness;
|
||||
|
||||
if (_thicknessCache.TryGetValue(k, out var result) == false)
|
||||
{
|
||||
result = new Thickness(k, 0, 0, 0);
|
||||
|
||||
_thicknessCache.Add(k, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static readonly LruCache<double, object> _thicknessCache = new LruCache<double, object>(8);
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
using WPFDark.Internals;
|
||||
|
||||
namespace WPFDark.Controls.Converters
|
||||
{
|
||||
public class TreeListViewItemMarginConverter : IValueConverter
|
||||
{
|
||||
public double Length { get; set; }
|
||||
public bool IsFirstColumn { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is TreeViewItem item))
|
||||
return new Thickness(0);
|
||||
|
||||
var right = Length * (item.GetDepth() + 1.0);
|
||||
var left = IsFirstColumn ? -6.0 : right * -1.0;
|
||||
|
||||
return new Thickness(left, 0, right, 0);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user