94 lines
2.9 KiB
C#
94 lines
2.9 KiB
C#
using HandyControl.Controls;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace Laservall.Solidworks.Common
|
|
{
|
|
public static class ComboBoxDataRegistry
|
|
{
|
|
private static readonly Dictionary<string, List<string>> _data =
|
|
new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
private static readonly List<string> _defaultItems = new List<string>();
|
|
|
|
public static void Register(string propertyName, List<string> items)
|
|
{
|
|
_data[propertyName] = items ?? new List<string>();
|
|
}
|
|
|
|
public static List<string> GetItems(string propertyName)
|
|
{
|
|
List<string> items;
|
|
if (_data.TryGetValue(propertyName, out items))
|
|
{
|
|
return items;
|
|
}
|
|
return _defaultItems;
|
|
}
|
|
}
|
|
|
|
public class ComboxPropertyEditor : PropertyEditorBase
|
|
{
|
|
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
|
{
|
|
var comboBox = new ComboBox();
|
|
comboBox.IsEditable = true;
|
|
var items = ComboBoxDataRegistry.GetItems(propertyItem.DisplayName);
|
|
comboBox.ItemsSource = items;
|
|
comboBox.SelectedItem = propertyItem.Value?.ToString();
|
|
comboBox.SelectionChanged += (s, e) =>
|
|
{
|
|
propertyItem.Value = comboBox.SelectedItem;
|
|
};
|
|
return comboBox;
|
|
}
|
|
|
|
public override DependencyProperty GetDependencyProperty()
|
|
{
|
|
return ComboBox.SelectedItemProperty;
|
|
}
|
|
}
|
|
|
|
public class CategoryComboxPropertyEditor : PropertyEditorBase
|
|
{
|
|
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
|
{
|
|
var comboBox = new ComboBox();
|
|
comboBox.IsEditable = true;
|
|
var items = ComboBoxDataRegistry.GetItems(propertyItem.DisplayName);
|
|
comboBox.ItemsSource = items;
|
|
comboBox.SelectedItem = propertyItem.Value?.ToString();
|
|
comboBox.SelectionChanged += (s, e) =>
|
|
{
|
|
propertyItem.Value = comboBox.SelectedItem;
|
|
};
|
|
return comboBox;
|
|
}
|
|
|
|
public override DependencyProperty GetDependencyProperty()
|
|
{
|
|
return ComboBox.SelectedItemProperty;
|
|
}
|
|
}
|
|
|
|
public class ReadOnlyTextPropertyEditor : PropertyEditorBase
|
|
{
|
|
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
|
{
|
|
return new System.Windows.Controls.TextBlock
|
|
{
|
|
VerticalAlignment = VerticalAlignment.Center
|
|
};
|
|
}
|
|
|
|
public override DependencyProperty GetDependencyProperty()
|
|
{
|
|
return System.Windows.Controls.TextBlock.TextProperty;
|
|
}
|
|
}
|
|
}
|