修改命名空间
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
|
||||
public class BooleanConverter<T> : IValueConverter
|
||||
{
|
||||
public BooleanConverter(T trueValue, T falseValue)
|
||||
{
|
||||
TrueValue = trueValue;
|
||||
FalseValue = falseValue;
|
||||
}
|
||||
|
||||
public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
value is bool boolValue &&
|
||||
boolValue
|
||||
? TrueValue
|
||||
: FalseValue;
|
||||
|
||||
public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => value is T tValue &&
|
||||
EqualityComparer<T>.Default.Equals(tValue, TrueValue);
|
||||
|
||||
public T FalseValue { get; set; }
|
||||
|
||||
public T TrueValue { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Windows;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters;
|
||||
|
||||
|
||||
public class BooleanToVisConverter : BooleanConverter<Visibility>
|
||||
{
|
||||
public BooleanToVisConverter() : base(Visibility.Visible, Visibility.Collapsed)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters;
|
||||
|
||||
public class ColorToBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
//var color = (SelectedColor)value;
|
||||
if (value is System.Windows.Media.Color color)
|
||||
{
|
||||
return new SolidColorBrush(color);
|
||||
}
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{ throw new NotImplementedException(); }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters;
|
||||
|
||||
public class ComparisonConverter : IValueConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Model属性->Control属性
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="targetType"></param>
|
||||
/// <param name="parameter"></param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
//value:ViewModel属性,枚举/数字/字符串
|
||||
//parameter:ConverterParameter,枚举/数字/字符串
|
||||
//return (string)parameter == (string)value;
|
||||
//绑定的枚举属性与控件转换参数一致则选中
|
||||
return value.Equals(parameter);
|
||||
//return (string)parameter == (string)value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 控件选中,将Converter参数传给模型属性
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="targetType"></param>
|
||||
/// <param name="parameter"></param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
//value:bool 比如RadioButton的check属性
|
||||
//parameter:ConverterParameter枚举
|
||||
//一样才传递给ViewModel
|
||||
//选中则返回枚举类
|
||||
return value is true ? parameter : Binding.DoNothing;
|
||||
//return (bool)value ? parameter : Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Markup;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters
|
||||
{
|
||||
public class EnumDescriptionExtension : MarkupExtension
|
||||
{
|
||||
private readonly object _enumValue;
|
||||
|
||||
public EnumDescriptionExtension(object enumValue)
|
||||
{
|
||||
_enumValue = enumValue;
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
if (_enumValue == null) return string.Empty;
|
||||
|
||||
var field = _enumValue.GetType().GetField(_enumValue.ToString());
|
||||
var attribute = field?.GetCustomAttributes(typeof(DescriptionAttribute), false)
|
||||
.FirstOrDefault() as DescriptionAttribute;
|
||||
|
||||
return attribute?.Description ?? _enumValue.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// 枚举类上加特性[TypeConverter(typeof(EnumDescriptionTypeConverter))]
|
||||
/// </summary>
|
||||
public class EnumDescriptionTypeConverter : EnumConverter
|
||||
{
|
||||
public EnumDescriptionTypeConverter(Type type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string))
|
||||
{
|
||||
if (null != value)
|
||||
{
|
||||
FieldInfo fi = value.GetType().GetField(value.ToString());
|
||||
|
||||
if (null != fi)
|
||||
{
|
||||
var attributes =
|
||||
(DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
|
||||
return ((attributes.Length > 0) && (!string.IsNullOrEmpty(attributes[0].Description)))
|
||||
? attributes[0].Description
|
||||
: value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Windows.Data;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// Description(描述特性)的枚举转换同时也是枚举源的集合
|
||||
/// </summary>
|
||||
public class EnumItemsSourceAndConverter : Collection<string>, IValueConverter
|
||||
{
|
||||
private IDictionary<object, object> displayNameToValueMap;
|
||||
private Type type;
|
||||
|
||||
private IDictionary<object, object> valueToDisplayNameMap;
|
||||
|
||||
public Type Type
|
||||
{
|
||||
get => type;
|
||||
set
|
||||
{
|
||||
if (!value.IsEnum)
|
||||
{
|
||||
throw new ArgumentException("不是枚举类型", $"{value}");
|
||||
}
|
||||
|
||||
type = value;
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 类属性到控件属性,源到目标
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="targetType"></param>
|
||||
/// <param name="parameter"></param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
//if (value != null)
|
||||
//{
|
||||
// int n = (int)value;
|
||||
// if (n == 0 || n == -1)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
//}
|
||||
return value == null
|
||||
? null
|
||||
: valueToDisplayNameMap.TryGetValue(value, out var value1)
|
||||
? value1
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 目标到源
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="targetType"></param>
|
||||
/// <param name="parameter"></param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value == null
|
||||
? null
|
||||
: displayNameToValueMap.TryGetValue(value, out var value1)
|
||||
? value1
|
||||
: null;
|
||||
}
|
||||
|
||||
private static object GetDescription(FieldInfo fieldInfo)
|
||||
{
|
||||
var descriptionAttribute = (DescriptionAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute));
|
||||
return descriptionAttribute != null ? descriptionAttribute.Description : fieldInfo.Name;
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
valueToDisplayNameMap = type.GetFields(BindingFlags.Static | BindingFlags.Public).ToDictionary(fi => fi.GetValue(null), GetDescription);
|
||||
displayNameToValueMap = valueToDisplayNameMap.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
|
||||
Clear();
|
||||
//当前converter的集合添加元素
|
||||
foreach (string name in displayNameToValueMap.Keys)
|
||||
{
|
||||
Add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters;
|
||||
|
||||
public class InvertBooleanConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value is bool b ? !b : value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value is bool b ? !b : value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Windows;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters;
|
||||
|
||||
public class InverterBooleanToVisConverter : BooleanConverter<Visibility>
|
||||
{
|
||||
public InverterBooleanToVisConverter() : base(Visibility.Collapsed, Visibility.Visible)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters
|
||||
{
|
||||
[ValueConversion(typeof(bool), typeof(Visibility))]
|
||||
public class BoolVisibilityConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return (value is bool b && b) ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value is Visibility v && v == Visibility.Visible;
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
[ValueConversion(typeof(bool), typeof(Visibility))]
|
||||
public class InverseBoolVisibilityConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return (bool)value! == false ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return (Visibility)value! != Visibility.Visible;
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
[ValueConversion(typeof(bool), typeof(bool))]
|
||||
public class BooleanConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return (bool)value!;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return (bool)value!;
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
[ValueConversion(typeof(bool), typeof(bool))]
|
||||
public class InverseBooleanConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return !(bool)value!;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return !(bool)value!;
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
|
||||
using System.Windows.Data;
|
||||
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts null or not null to a <see cref="Visibility" />.
|
||||
/// </summary>
|
||||
public class NotNullToVisibilityConverter : IValueConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// The visibility value if the argument is null.
|
||||
/// </summary>
|
||||
public Visibility NullValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="NotNullToVisibilityConverter" />.
|
||||
/// </summary>
|
||||
public NotNullToVisibilityConverter()
|
||||
{
|
||||
NullValue = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value == null ? NullValue : Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
using Color = System.Windows.Media.Color;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// Autodesk颜色转Windows系统颜色
|
||||
/// </summary>
|
||||
public class Rv2WinColorConverter : IValueConverter
|
||||
{
|
||||
public static Converters.Rv2WinColorConverter Instance { get; } = new Converters.Rv2WinColorConverter();
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var color = (Autodesk.Revit.DB.Color)value;
|
||||
//if (Autodesk.Revit.DB.SelectedColor.InvalidColorValue)
|
||||
//{
|
||||
//}
|
||||
if (color is { IsValid: true })
|
||||
{
|
||||
var rgb = Color.FromRgb(color.Red, color.Green, color.Blue);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
return new Color();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value is Color rgb ? new Autodesk.Revit.DB.Color(rgb.R, rgb.G, rgb.B) : (object)Autodesk.Revit.DB.Color.InvalidColorValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters
|
||||
{
|
||||
public class SearchFamilyValueConverter : IMultiValueConverter
|
||||
{
|
||||
public static Converters.SearchFamilyValueConverter Instance { get; } = new Converters.SearchFamilyValueConverter();
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var cellText = values[0] == null ? string.Empty : values[0].ToString();
|
||||
var searchText = values[1] as string;
|
||||
var cell = values[2] as DataGridCell;
|
||||
|
||||
var head = cell?.Column?.Header?.ToString();
|
||||
|
||||
return head is "族名称" && !string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(cellText) ? cellText.Contains(searchText) : (object)false;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters
|
||||
{
|
||||
public class SearchTypeValueConverter : IMultiValueConverter
|
||||
{
|
||||
public static Converters.SearchTypeValueConverter Instance { get; } = new Converters.SearchTypeValueConverter();
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var cellText = values[0] == null ? string.Empty : values[0].ToString();
|
||||
var searchText = values[1] as string;
|
||||
var cell = values[2] as DataGridCell;
|
||||
|
||||
var head = cell?.Column?.Header?.ToString();
|
||||
|
||||
return head is "族类型" && !string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(cellText) ? cellText.Contains(searchText) : (object)false;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Windows.Data;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.UI.Converters;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.UI;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters;
|
||||
|
||||
public class SearchValueConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var cellText = values[0] == null ? string.Empty : values[0].ToString();
|
||||
var searchText = values[1] as string;
|
||||
if (!string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(cellText))
|
||||
{
|
||||
return cellText.ToLower().Contains(searchText.ToLower());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user