首次上传
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace MECF.Framework.UI.Core.ExtendedControls
|
||||
{
|
||||
public class BindingProxy : Freezable
|
||||
{
|
||||
#region Overrides of Freezable
|
||||
|
||||
protected override Freezable CreateInstanceCore()
|
||||
{
|
||||
return new BindingProxy();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public object Data
|
||||
{
|
||||
get { return (object)GetValue(DataProperty); }
|
||||
set { SetValue(DataProperty, value); }
|
||||
}
|
||||
|
||||
// Using a DependencyProperty as the backing store for Data. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty DataProperty =
|
||||
DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<UserControl x:Class="MECF.Framework.UI.Core.ExtendedControls.ObjectInTreeView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:extendedControls="clr-namespace:MECF.Framework.UI.Core.ExtendedControls"
|
||||
mc:Ignorable="d"
|
||||
x:Name="self"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<TreeView ItemsSource="{Binding TreeNodes, ElementName=self}">
|
||||
<TreeView.Resources>
|
||||
<Style TargetType="{x:Type TreeViewItem}">
|
||||
<Setter Property="IsExpanded" Value="True">
|
||||
</Setter>
|
||||
</Style>
|
||||
<HierarchicalDataTemplate DataType="{x:Type extendedControls:ObjectTreeNode}" ItemsSource="{Binding Path=Children}">
|
||||
<TreeViewItem>
|
||||
<TreeViewItem.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding Path=Name}"/>
|
||||
<TextBlock Text=" : "/>
|
||||
<TextBlock Text="{Binding Path=Value}"/>
|
||||
</StackPanel>
|
||||
</TreeViewItem.Header>
|
||||
</TreeViewItem>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.Resources>
|
||||
</TreeView>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace MECF.Framework.UI.Core.ExtendedControls
|
||||
{
|
||||
/// <summary>
|
||||
/// ObjectInTreeView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ObjectInTreeView : UserControl
|
||||
{
|
||||
public ObjectInTreeView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public object ObjectToVisualize
|
||||
{
|
||||
get { return (object) GetValue(ObjectToVisualizeProperty); }
|
||||
set { SetValue(ObjectToVisualizeProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ObjectToVisualizeProperty =
|
||||
DependencyProperty.Register("ObjectToVisualize", typeof(object), typeof(ObjectInTreeView),
|
||||
new PropertyMetadata(null, OnObjectChanged));
|
||||
|
||||
private static void OnObjectChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
ObjectTreeNode tree = ObjectTreeNode.CreateTree(e.NewValue);
|
||||
(d as ObjectInTreeView).TreeNodes = new List<ObjectTreeNode>() {tree};
|
||||
}
|
||||
|
||||
public List<ObjectTreeNode> TreeNodes
|
||||
{
|
||||
get { return (List<ObjectTreeNode>) GetValue(TreeNodesProperty); }
|
||||
set { SetValue(TreeNodesProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TreeNodesProperty =
|
||||
DependencyProperty.Register("TreeNodes", typeof(List<ObjectTreeNode>), typeof(ObjectInTreeView),
|
||||
new PropertyMetadata(null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace MECF.Framework.UI.Core.ExtendedControls
|
||||
{
|
||||
public class ObjectTreeNode
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
public List<ObjectTreeNode> Children { get; set; } = new List<ObjectTreeNode>();
|
||||
|
||||
public static ObjectTreeNode CreateTree(object obj)
|
||||
{
|
||||
JavaScriptSerializer jss = new JavaScriptSerializer();
|
||||
var serialized = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
|
||||
Dictionary<string, object> dic = jss.Deserialize<Dictionary<string, object>>(serialized);
|
||||
var root = new ObjectTreeNode();
|
||||
root.Name = "Root";
|
||||
BuildTree(dic, root);
|
||||
return root;
|
||||
}
|
||||
|
||||
private static void BuildTree(object item, ObjectTreeNode node)
|
||||
{
|
||||
if (item is KeyValuePair<string, object>)
|
||||
{
|
||||
KeyValuePair<string, object> kv = (KeyValuePair<string, object>) item;
|
||||
ObjectTreeNode keyValueNode = new ObjectTreeNode();
|
||||
keyValueNode.Name = kv.Key;
|
||||
keyValueNode.Value = GetValueAsString(kv.Value);
|
||||
node.Children.Add(keyValueNode);
|
||||
BuildTree(kv.Value, keyValueNode);
|
||||
}
|
||||
else if (item is ArrayList)
|
||||
{
|
||||
ArrayList list = (ArrayList) item;
|
||||
int index = 0;
|
||||
foreach (object value in list)
|
||||
{
|
||||
ObjectTreeNode arrayItem = new ObjectTreeNode();
|
||||
arrayItem.Name = $"[{index}]";
|
||||
arrayItem.Value = "";
|
||||
node.Children.Add(arrayItem);
|
||||
BuildTree(value, arrayItem);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
else if (item is Dictionary<string, object>)
|
||||
{
|
||||
Dictionary<string, object> dictionary = (Dictionary<string, object>) item;
|
||||
foreach (KeyValuePair<string, object> d in dictionary)
|
||||
{
|
||||
BuildTree(d, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetValueAsString(object value)
|
||||
{
|
||||
if (value == null)
|
||||
return "null";
|
||||
var type = value.GetType();
|
||||
if (type.IsArray)
|
||||
{
|
||||
return "[]";
|
||||
}
|
||||
|
||||
if (value is ArrayList)
|
||||
{
|
||||
var arr = value as ArrayList;
|
||||
return $"[{arr.Count}]";
|
||||
}
|
||||
|
||||
if (type.IsGenericType)
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Interactivity;
|
||||
|
||||
namespace MECF.Framework.UI.Core.ExtendedControls
|
||||
{
|
||||
public class BindableSelectedItemBehavior : Behavior<TreeView>
|
||||
{
|
||||
#region SelectedItem Property
|
||||
|
||||
public object SelectedItem
|
||||
{
|
||||
get { return (object)GetValue(SelectedItemProperty); }
|
||||
set { SetValue(SelectedItemProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SelectedItemProperty =
|
||||
DependencyProperty.Register("SelectedItem", typeof(object), typeof(BindableSelectedItemBehavior), new UIPropertyMetadata(null, OnSelectedItemChanged));
|
||||
|
||||
private static void OnSelectedItemChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var item = e.NewValue as TreeViewItem;
|
||||
if (item != null)
|
||||
{
|
||||
item.SetValue(TreeViewItem.IsSelectedProperty, true);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected override void OnAttached()
|
||||
{
|
||||
base.OnAttached();
|
||||
|
||||
this.AssociatedObject.SelectedItemChanged += OnTreeViewSelectedItemChanged;
|
||||
}
|
||||
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
base.OnDetaching();
|
||||
|
||||
if (this.AssociatedObject != null)
|
||||
{
|
||||
this.AssociatedObject.SelectedItemChanged -= OnTreeViewSelectedItemChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTreeViewSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
||||
{
|
||||
this.SelectedItem = e.NewValue;
|
||||
}
|
||||
}
|
||||
|
||||
public class TreeViewHelper
|
||||
{
|
||||
private static Dictionary<DependencyObject, TreeViewSelectedItemBehavior> behaviors = new Dictionary<DependencyObject, TreeViewSelectedItemBehavior>();
|
||||
|
||||
public static object GetSelectedItem(DependencyObject obj)
|
||||
{
|
||||
return (object)obj.GetValue(SelectedItemProperty);
|
||||
}
|
||||
|
||||
public static void SetSelectedItem(DependencyObject obj, object value)
|
||||
{
|
||||
obj.SetValue(SelectedItemProperty, value);
|
||||
}
|
||||
|
||||
// Using a DependencyProperty as the backing store for SelectedItem. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty SelectedItemProperty =
|
||||
DependencyProperty.RegisterAttached("SelectedItem", typeof(object), typeof(TreeViewHelper), new UIPropertyMetadata(null, SelectedItemChanged));
|
||||
|
||||
private static void SelectedItemChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (!(obj is TreeView))
|
||||
return;
|
||||
|
||||
if (!behaviors.ContainsKey(obj))
|
||||
behaviors.Add(obj, new TreeViewSelectedItemBehavior(obj as TreeView));
|
||||
|
||||
TreeViewSelectedItemBehavior view = behaviors[obj];
|
||||
view.ChangeSelectedItem(e.NewValue);
|
||||
}
|
||||
|
||||
private class TreeViewSelectedItemBehavior
|
||||
{
|
||||
TreeView view;
|
||||
public TreeViewSelectedItemBehavior(TreeView view)
|
||||
{
|
||||
this.view = view;
|
||||
view.SelectedItemChanged += (sender, e) => SetSelectedItem(view, e.NewValue);
|
||||
}
|
||||
|
||||
internal void ChangeSelectedItem(object p)
|
||||
{
|
||||
TreeViewItem item = (TreeViewItem)view.ItemContainerGenerator.ContainerFromItem(p);
|
||||
item.IsSelected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,375 @@
|
||||
// *********************************************************************
|
||||
// PLEASE DO NOT REMOVE THIS DISCLAIMER
|
||||
//
|
||||
// WpfPropertyGrid - By Jaime Olivares
|
||||
// July 11, 2011
|
||||
// Article site: http://www.codeproject.com/KB/grid/WpfPropertyGrid.aspx
|
||||
// Author site: www.jaimeolivares.com
|
||||
// License: Code Project Open License (CPOL)
|
||||
//
|
||||
// *********************************************************************
|
||||
|
||||
using System.Activities.Presentation;
|
||||
using System.Activities.Presentation.Model;
|
||||
using System.Activities.Presentation.View;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace System.Windows.Controls
|
||||
{
|
||||
public enum PropertySort
|
||||
{
|
||||
NoSort = 0,
|
||||
Alphabetical = 1,
|
||||
Categorized = 2,
|
||||
CategorizedAlphabetical = 3
|
||||
};
|
||||
|
||||
/// <summary>WPF Native PropertyGrid class, uses Workflow Foundation's PropertyInspector</summary>
|
||||
public class WpfPropertyGrid : Grid
|
||||
{
|
||||
#region Private fields
|
||||
private WorkflowDesigner Designer;
|
||||
private MethodInfo RefreshMethod;
|
||||
private MethodInfo OnSelectionChangedMethod;
|
||||
private MethodInfo IsInAlphaViewMethod;
|
||||
private TextBlock SelectionTypeLabel;
|
||||
private Control PropertyToolBar;
|
||||
private Border HelpText;
|
||||
private GridSplitter Splitter;
|
||||
private double HelpTextHeight = 60;
|
||||
#endregion
|
||||
|
||||
#region Public properties
|
||||
/// <summary>Get or sets the selected object. Can be null.</summary>
|
||||
public object SelectedObject
|
||||
{
|
||||
get { return GetValue(SelectedObjectProperty); }
|
||||
set { SetValue(SelectedObjectProperty, value); }
|
||||
}
|
||||
/// <summary>Get or sets the selected object collection. Returns empty array by default.</summary>
|
||||
public object[] SelectedObjects
|
||||
{
|
||||
get { return GetValue(SelectedObjectsProperty) as object[]; }
|
||||
set { SetValue(SelectedObjectsProperty, value); }
|
||||
}
|
||||
/// <summary>XAML information with PropertyGrid's font and color information</summary>
|
||||
/// <seealso>Documentation for WorkflowDesigner.PropertyInspectorFontAndColorData</seealso>
|
||||
public string FontAndColorData
|
||||
{
|
||||
set
|
||||
{
|
||||
Designer.PropertyInspectorFontAndColorData = value;
|
||||
}
|
||||
}
|
||||
/// <summary>Shows the description area on the top of the control</summary>
|
||||
public bool HelpVisible
|
||||
{
|
||||
get { return (bool)GetValue(HelpVisibleProperty); }
|
||||
set { SetValue(HelpVisibleProperty, value); }
|
||||
}
|
||||
/// <summary>Shows the tolbar on the top of the control</summary>
|
||||
public bool ToolbarVisible
|
||||
{
|
||||
get { return (bool)GetValue(ToolbarVisibleProperty); }
|
||||
set { SetValue(ToolbarVisibleProperty, value); }
|
||||
}
|
||||
public PropertySort PropertySort
|
||||
{
|
||||
get { return (PropertySort)GetValue(PropertySortProperty); }
|
||||
set { SetValue(PropertySortProperty, value); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dependency properties registration
|
||||
public static readonly DependencyProperty SelectedObjectProperty =
|
||||
DependencyProperty.Register("SelectedObject", typeof(object), typeof(WpfPropertyGrid),
|
||||
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, SelectedObjectPropertyChanged));
|
||||
|
||||
public static readonly DependencyProperty SelectedObjectsProperty =
|
||||
DependencyProperty.Register("SelectedObjects", typeof(object[]), typeof(WpfPropertyGrid),
|
||||
new FrameworkPropertyMetadata(new object[0], FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, SelectedObjectsPropertyChanged, CoerceSelectedObjects));
|
||||
|
||||
public static readonly DependencyProperty HelpVisibleProperty =
|
||||
DependencyProperty.Register("HelpVisible", typeof(bool), typeof(WpfPropertyGrid),
|
||||
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, HelpVisiblePropertyChanged));
|
||||
public static readonly DependencyProperty ToolbarVisibleProperty =
|
||||
DependencyProperty.Register("ToolbarVisible", typeof(bool), typeof(WpfPropertyGrid),
|
||||
new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ToolbarVisiblePropertyChanged));
|
||||
public static readonly DependencyProperty PropertySortProperty =
|
||||
DependencyProperty.Register("PropertySort", typeof(PropertySort), typeof(WpfPropertyGrid),
|
||||
new FrameworkPropertyMetadata(PropertySort.CategorizedAlphabetical, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, PropertySortPropertyChanged));
|
||||
#endregion
|
||||
|
||||
#region Dependency properties events
|
||||
private static object CoerceSelectedObject(DependencyObject d, object value)
|
||||
{
|
||||
WpfPropertyGrid pg = d as WpfPropertyGrid;
|
||||
|
||||
object[] collection = pg.GetValue(SelectedObjectsProperty) as object[];
|
||||
|
||||
return collection.Length == 0 ? null : value;
|
||||
}
|
||||
private static object CoerceSelectedObjects(DependencyObject d, object value)
|
||||
{
|
||||
WpfPropertyGrid pg = d as WpfPropertyGrid;
|
||||
|
||||
object single = pg.GetValue(SelectedObjectsProperty);
|
||||
|
||||
return single == null ? new object[0] : value;
|
||||
}
|
||||
|
||||
private static void SelectedObjectPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
WpfPropertyGrid pg = source as WpfPropertyGrid;
|
||||
pg.CoerceValue(SelectedObjectsProperty);
|
||||
|
||||
if (e.NewValue == null)
|
||||
{
|
||||
pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { null });
|
||||
pg.SelectionTypeLabel.Text = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
var context = new EditingContext();
|
||||
var mtm = new ModelTreeManager(context);
|
||||
mtm.Load(e.NewValue);
|
||||
Selection selection = Selection.Select(context, mtm.Root);
|
||||
|
||||
pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { selection });
|
||||
pg.SelectionTypeLabel.Text = e.NewValue.GetType().Name;
|
||||
}
|
||||
|
||||
pg.ChangeHelpText(string.Empty, string.Empty);
|
||||
}
|
||||
private static void SelectedObjectsPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
WpfPropertyGrid pg = source as WpfPropertyGrid;
|
||||
pg.CoerceValue(SelectedObjectsProperty);
|
||||
|
||||
object[] collection = e.NewValue as object[];
|
||||
|
||||
if (collection.Length == 0)
|
||||
{
|
||||
pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { null });
|
||||
pg.SelectionTypeLabel.Text = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool same = true;
|
||||
Type first = null;
|
||||
|
||||
var context = new EditingContext();
|
||||
var mtm = new ModelTreeManager(context);
|
||||
Selection selection = null;
|
||||
|
||||
// Accumulates the selection and determines the type to be shown in the top of the PG
|
||||
for (int i = 0; i < collection.Length; i++)
|
||||
{
|
||||
mtm.Load(collection[i]);
|
||||
if (i == 0)
|
||||
{
|
||||
selection = Selection.Select(context, mtm.Root);
|
||||
first = collection[0].GetType();
|
||||
}
|
||||
else
|
||||
{
|
||||
selection = Selection.Union(context, mtm.Root);
|
||||
if (!collection[i].GetType().Equals(first))
|
||||
same = false;
|
||||
}
|
||||
}
|
||||
|
||||
pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { selection });
|
||||
pg.SelectionTypeLabel.Text = same ? first.Name + " <multiple>" : "Object <multiple>";
|
||||
}
|
||||
|
||||
pg.ChangeHelpText(string.Empty, string.Empty);
|
||||
}
|
||||
private static void HelpVisiblePropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
WpfPropertyGrid pg = source as WpfPropertyGrid;
|
||||
|
||||
if (e.NewValue != e.OldValue)
|
||||
{
|
||||
if (e.NewValue.Equals(true))
|
||||
{
|
||||
pg.RowDefinitions[1].Height = new GridLength(5);
|
||||
pg.RowDefinitions[2].Height = new GridLength(pg.HelpTextHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
pg.HelpTextHeight = pg.RowDefinitions[2].Height.Value;
|
||||
pg.RowDefinitions[1].Height = new GridLength(0);
|
||||
pg.RowDefinitions[2].Height = new GridLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void ToolbarVisiblePropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
WpfPropertyGrid pg = source as WpfPropertyGrid;
|
||||
pg.PropertyToolBar.Visibility = e.NewValue.Equals(true) ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
private static void PropertySortPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
WpfPropertyGrid pg = source as WpfPropertyGrid;
|
||||
PropertySort sort = (PropertySort)e.NewValue;
|
||||
|
||||
bool isAlpha = (sort == PropertySort.Alphabetical || sort == PropertySort.NoSort);
|
||||
pg.IsInAlphaViewMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { isAlpha });
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>Default constructor, creates the UIElements including a PropertyInspector</summary>
|
||||
public WpfPropertyGrid()
|
||||
{
|
||||
this.ColumnDefinitions.Add(new ColumnDefinition());
|
||||
this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
|
||||
this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0) });
|
||||
this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0) });
|
||||
|
||||
this.Designer = new WorkflowDesigner();
|
||||
TextBlock title = new TextBlock()
|
||||
{
|
||||
Visibility = Windows.Visibility.Visible,
|
||||
TextWrapping = TextWrapping.NoWrap,
|
||||
TextTrimming = TextTrimming.CharacterEllipsis,
|
||||
FontWeight = FontWeights.Bold
|
||||
};
|
||||
TextBlock descrip = new TextBlock()
|
||||
{
|
||||
Visibility = Windows.Visibility.Visible,
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
TextTrimming = TextTrimming.CharacterEllipsis
|
||||
};
|
||||
DockPanel dock = new DockPanel()
|
||||
{
|
||||
Visibility = Windows.Visibility.Visible,
|
||||
LastChildFill = true,
|
||||
Margin = new Thickness(3,0,3,0)
|
||||
};
|
||||
|
||||
title.SetValue(DockPanel.DockProperty, Dock.Top);
|
||||
dock.Children.Add(title);
|
||||
dock.Children.Add(descrip);
|
||||
this.HelpText = new Border()
|
||||
{
|
||||
Visibility = Windows.Visibility.Visible,
|
||||
BorderBrush = SystemColors.ActiveBorderBrush,
|
||||
Background = SystemColors.ControlBrush,
|
||||
BorderThickness = new Thickness(1),
|
||||
Child = dock
|
||||
};
|
||||
this.Splitter = new GridSplitter()
|
||||
{
|
||||
Visibility = Windows.Visibility.Visible,
|
||||
ResizeDirection = GridResizeDirection.Rows,
|
||||
Height=5,
|
||||
HorizontalAlignment= Windows.HorizontalAlignment.Stretch
|
||||
};
|
||||
|
||||
var inspector = Designer.PropertyInspectorView;
|
||||
inspector.Visibility = Visibility.Visible;
|
||||
inspector.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Stretch);
|
||||
|
||||
this.Splitter.SetValue(Grid.RowProperty, 1);
|
||||
this.Splitter.SetValue(Grid.ColumnProperty, 0);
|
||||
|
||||
this.HelpText.SetValue(Grid.RowProperty, 2);
|
||||
this.HelpText.SetValue(Grid.ColumnProperty, 0);
|
||||
|
||||
Binding binding = new Binding("Parent.Background");
|
||||
title.SetBinding(BackgroundProperty, binding);
|
||||
descrip.SetBinding(BackgroundProperty, binding);
|
||||
|
||||
this.Children.Add(inspector);
|
||||
this.Children.Add(this.Splitter);
|
||||
this.Children.Add(this.HelpText);
|
||||
|
||||
Type inspectorType = inspector.GetType();
|
||||
var props = inspectorType.GetProperties(Reflection.BindingFlags.Public | Reflection.BindingFlags.NonPublic | Reflection.BindingFlags.Instance |
|
||||
Reflection.BindingFlags.DeclaredOnly);
|
||||
|
||||
var methods = inspectorType.GetMethods(Reflection.BindingFlags.Public | Reflection.BindingFlags.NonPublic | Reflection.BindingFlags.Instance |
|
||||
Reflection.BindingFlags.DeclaredOnly);
|
||||
|
||||
this.RefreshMethod = inspectorType.GetMethod("RefreshPropertyList",
|
||||
Reflection.BindingFlags.NonPublic | Reflection.BindingFlags.Instance | Reflection.BindingFlags.DeclaredOnly);
|
||||
this.IsInAlphaViewMethod = inspectorType.GetMethod("set_IsInAlphaView",
|
||||
Reflection.BindingFlags.Public | Reflection.BindingFlags.Instance | Reflection.BindingFlags.DeclaredOnly);
|
||||
this.OnSelectionChangedMethod = inspectorType.GetMethod("OnSelectionChanged",
|
||||
Reflection.BindingFlags.Public | Reflection.BindingFlags.Instance | Reflection.BindingFlags.DeclaredOnly);
|
||||
this.SelectionTypeLabel = inspectorType.GetMethod("get_SelectionTypeLabel",
|
||||
Reflection.BindingFlags.Public | Reflection.BindingFlags.NonPublic | Reflection.BindingFlags.Instance |
|
||||
Reflection.BindingFlags.DeclaredOnly).Invoke(inspector, new object[0]) as TextBlock;
|
||||
this.PropertyToolBar = inspectorType.GetMethod("get_PropertyToolBar",
|
||||
Reflection.BindingFlags.Public | Reflection.BindingFlags.NonPublic | Reflection.BindingFlags.Instance |
|
||||
Reflection.BindingFlags.DeclaredOnly).Invoke(inspector, new object[0]) as Control;
|
||||
inspectorType.GetEvent("GotFocus").AddEventHandler(this,
|
||||
Delegate.CreateDelegate(typeof(RoutedEventHandler), this, "GotFocusHandler", false));
|
||||
|
||||
this.SelectionTypeLabel.Text = string.Empty;
|
||||
}
|
||||
/// <summary>Updates the PropertyGrid's properties</summary>
|
||||
public void RefreshPropertyList()
|
||||
{
|
||||
RefreshMethod.Invoke(Designer.PropertyInspectorView, new object[] { false });
|
||||
}
|
||||
|
||||
/// <summary>Traps the change of focused property and updates the help text</summary>
|
||||
/// <param name="sender">Not used</param>
|
||||
/// <param name="args">Points to the source control containing the selected property</param>
|
||||
private void GotFocusHandler(object sender, RoutedEventArgs args)
|
||||
{
|
||||
//if (args.OriginalSource is TextBlock)
|
||||
//{
|
||||
string title = string.Empty;
|
||||
string descrip = string.Empty;
|
||||
var theSelectedObjects = this.GetValue(SelectedObjectsProperty) as object[];
|
||||
|
||||
if (theSelectedObjects != null && theSelectedObjects.Length > 0)
|
||||
{
|
||||
Type first = theSelectedObjects[0].GetType();
|
||||
for (int i = 1; i < theSelectedObjects.Length; i++)
|
||||
{
|
||||
if (!theSelectedObjects[i].GetType().Equals(first))
|
||||
{
|
||||
ChangeHelpText(title, descrip);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
object data = (args.OriginalSource as FrameworkElement).DataContext;
|
||||
PropertyInfo propEntry = data.GetType().GetProperty("PropertyEntry");
|
||||
if (propEntry == null)
|
||||
{
|
||||
propEntry = data.GetType().GetProperty("ParentProperty");
|
||||
}
|
||||
|
||||
if (propEntry != null)
|
||||
{
|
||||
object propEntryValue = propEntry.GetValue(data, null);
|
||||
string propName = propEntryValue.GetType().GetProperty("PropertyName").GetValue(propEntryValue, null) as string;
|
||||
title = propEntryValue.GetType().GetProperty("DisplayName").GetValue(propEntryValue, null) as string;
|
||||
PropertyInfo property = theSelectedObjects[0].GetType().GetProperty(propName);
|
||||
object[] attrs = property.GetCustomAttributes(typeof(DescriptionAttribute), true);
|
||||
|
||||
if (attrs != null && attrs.Length > 0)
|
||||
descrip = (attrs[0] as DescriptionAttribute).Description;
|
||||
}
|
||||
ChangeHelpText(title, descrip);
|
||||
}
|
||||
//}
|
||||
}
|
||||
/// <summary>Changes the text help area contents</summary>
|
||||
/// <param name="title">Title in bold</param>
|
||||
/// <param name="descrip">Description with ellipsis</param>
|
||||
private void ChangeHelpText(string title, string descrip)
|
||||
{
|
||||
DockPanel dock = this.HelpText.Child as DockPanel;
|
||||
(dock.Children[0] as TextBlock).Text = title;
|
||||
(dock.Children[1] as TextBlock).Text = descrip;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user