12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using InABox.Core;
- namespace InABox.DynamicGrid;
- internal class JsonEditorControl : DynamicEditorControl<string, JsonEditor>
- {
- static JsonEditorControl()
- {
- //DynamicEditorControlFactory.Register<JsonEditorControl, JsonEditor>();
- }
-
- private Button _button;
- private string _value = "";
- public JsonEditorControl()
- {
- Width = 150;
- }
- public override int DesiredHeight()
- {
- return 25;
- }
- public override int DesiredWidth()
- {
- return 150;
- }
- public override void SetColor(Color color)
- {
- _button.Background = new SolidColorBrush(color);
- }
- public override void SetFocus()
- {
- // Not Sure what to do here?
- }
- public override void Configure()
- {
- }
- protected override FrameworkElement CreateEditor()
- {
- _button = new Button();
- _button.Content = "Edit";
- _button.Click += _button_Click;
- return _button;
- }
- private void _button_Click(object sender, RoutedEventArgs e)
- {
- var type = (EditorDefinition as JsonEditor).Type;
- var listtype = typeof(List<>).MakeGenericType(type);
- var list = Activator.CreateInstance(listtype) as IList;
- if (!string.IsNullOrWhiteSpace(_value))
- Serialization.DeserializeInto(_value, list);
- var array = new object[list.Count];
- list.CopyTo(array, 0);
- var grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicGrid<>), type);
- if (grid.EditItems(array))
- {
- _value = Serialization.Serialize(list, true);
- CheckChanged();
- }
- }
- protected override string RetrieveValue()
- {
- return _value;
- }
- protected override void UpdateValue(string value)
- {
- _value = "";
- }
- }
|