|
@@ -2,49 +2,73 @@ using System.Linq;
|
|
|
using System.Linq.Expressions;
|
|
|
using System.Reflection;
|
|
|
using System.Windows.Controls;
|
|
|
+using System.Windows.Media;
|
|
|
using InABox.Core;
|
|
|
+using InABox.WPF;
|
|
|
|
|
|
namespace InABox.DynamicGrid;
|
|
|
|
|
|
-public class PropertyNode<T> : ComboBox
|
|
|
+public class PropertyNode<T> : Button
|
|
|
{
|
|
|
public delegate void PropertyChangedHandler(string? property);
|
|
|
|
|
|
public event PropertyChangedHandler? PropertyChanged;
|
|
|
|
|
|
- public string? SelectedProperty => SelectedItem as string;
|
|
|
+ private string? _selectedProperty;
|
|
|
+ public string? SelectedProperty
|
|
|
+ {
|
|
|
+ get => _selectedProperty;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ _selectedProperty = value;
|
|
|
+ Content = _selectedProperty;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private readonly string[] ColumnNames;
|
|
|
|
|
|
public PropertyNode(Expression expression)
|
|
|
{
|
|
|
- SetResourceReference(StyleProperty, typeof(ComboBox));
|
|
|
-
|
|
|
VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
|
|
|
VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
|
|
|
+ HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
|
|
|
MinWidth = 100;
|
|
|
|
|
|
+ Padding = new System.Windows.Thickness(5, 0, 5, 0);
|
|
|
+ Background = new LinearGradientBrush(new GradientStopCollection()
|
|
|
+ {
|
|
|
+ new(Color.FromRgb(0xF0, 0xF0, 0xF0), 0.0),
|
|
|
+ new(Color.FromRgb(0xE5, 0xE5, 0xE5), 1.0),
|
|
|
+ })
|
|
|
+ {
|
|
|
+ StartPoint = new(0, 0),
|
|
|
+ EndPoint = new(0, 1),
|
|
|
+ };
|
|
|
+ BorderBrush = Color.FromRgb(0xAC, 0xAC, 0xAC).ToBrush();
|
|
|
+
|
|
|
var properties = DatabaseSchema.Properties(typeof(T))
|
|
|
.Where(x => x.IsSerializable)
|
|
|
.Select(x => x.Name)
|
|
|
.ToList();
|
|
|
properties.Sort();
|
|
|
- foreach (var property in properties)
|
|
|
- {
|
|
|
- Items.Add(property);
|
|
|
- }
|
|
|
+ ColumnNames = properties.ToArray();
|
|
|
if (CoreUtils.TryFindMemberExpression(expression, out var mexp))
|
|
|
- SelectedItem = CoreUtils.GetFullPropertyName(mexp, ".");
|
|
|
+ SelectedProperty = CoreUtils.GetFullPropertyName(mexp, ".");
|
|
|
|
|
|
- SelectionChanged += ComboBox_SelectionChanged;
|
|
|
+ Click += PropertyNode_Click;
|
|
|
}
|
|
|
|
|
|
- public void Clear()
|
|
|
+ private void PropertyNode_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
|
{
|
|
|
- SelectedIndex = -1;
|
|
|
+ if(DynamicGridColumnNameSelectorGrid.SelectColumnName(ColumnNames, out var value))
|
|
|
+ {
|
|
|
+ SelectedProperty = value;
|
|
|
+ PropertyChanged?.Invoke(value);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
+ public void Clear()
|
|
|
{
|
|
|
- var selected = SelectedItem as string;
|
|
|
- PropertyChanged?.Invoke(selected);
|
|
|
+ SelectedProperty = null;
|
|
|
}
|
|
|
}
|