|
@@ -0,0 +1,88 @@
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Windows;
|
|
|
+using System.Windows.Controls;
|
|
|
+using System.Windows.Media;
|
|
|
+using InABox.Core;
|
|
|
+
|
|
|
+namespace InABox.DynamicGrid
|
|
|
+{
|
|
|
+ public class EmbeddedListEditorControl : DynamicEditorControl<string>
|
|
|
+ {
|
|
|
+ private Button Editor;
|
|
|
+
|
|
|
+ private string _data = "";
|
|
|
+
|
|
|
+ public string? Label { get; set; }
|
|
|
+
|
|
|
+ public Type DataType { get; set; }
|
|
|
+
|
|
|
+ protected override FrameworkElement CreateEditor()
|
|
|
+ {
|
|
|
+ Editor = new Button
|
|
|
+ {
|
|
|
+ Content = Label,
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Stretch,
|
|
|
+ VerticalAlignment = VerticalAlignment.Stretch,
|
|
|
+ VerticalContentAlignment = VerticalAlignment.Center,
|
|
|
+ };
|
|
|
+ Editor.Click += Editor_Click;
|
|
|
+
|
|
|
+ return Editor;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Editor_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ var listtype = typeof(List<>).MakeGenericType(DataType);
|
|
|
+ var list = Serialization.Deserialize(listtype, _data) ?? (IList)Activator.CreateInstance(listtype)!;
|
|
|
+ var gridtype = DynamicGridUtils.FindDynamicGrid(typeof(DynamicItemsListGrid<>), DataType);
|
|
|
+
|
|
|
+ var grid = Activator.CreateInstance(gridtype, new object[] { list })!;
|
|
|
+ ((IDynamicGrid)grid).Options
|
|
|
+ .BeginUpdate()
|
|
|
+ .Add(DynamicGridOption.AddRows)
|
|
|
+ .Add(DynamicGridOption.DeleteRows)
|
|
|
+ .Add(DynamicGridOption.DirectEdit)
|
|
|
+ .Add(DynamicGridOption.RecordCount)
|
|
|
+ .EndUpdate();
|
|
|
+ ((IDynamicGrid)grid).Refresh(true, true);
|
|
|
+ var window = new DynamicContentDialog((FrameworkElement)grid);
|
|
|
+ if (window.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ _data = Serialization.Serialize(list);
|
|
|
+ CheckChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public override int DesiredHeight()
|
|
|
+ {
|
|
|
+ return 25;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override int DesiredWidth()
|
|
|
+ {
|
|
|
+ return 100;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override string RetrieveValue()
|
|
|
+ {
|
|
|
+ return _data;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void UpdateValue(string value)
|
|
|
+ {
|
|
|
+ _data = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SetFocus()
|
|
|
+ {
|
|
|
+ Editor.Focus();
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SetColor(Color color)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|