更新
This commit is contained in:
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user