5 using System.Collections.Generic;
7 using System.Windows.Controls;
8 using System.Windows.Input;
10 using SiliconStudio.Presentation.Collections;
11 using SiliconStudio.Presentation.Extensions;
13 namespace SiliconStudio.Presentation.Controls
17 private readonly ObservableList<PropertyViewItem> properties =
new ObservableList<PropertyViewItem>();
20 public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register(
"IsExpanded", typeof(
bool), typeof(
PropertyViewItem),
new FrameworkPropertyMetadata(
false, OnIsExpandedChanged));
22 public static readonly DependencyProperty CanBeHoveredProperty = DependencyProperty.Register(
"CanBeHovered", typeof(
bool), typeof(
PropertyViewItem),
new FrameworkPropertyMetadata(
true));
24 public static readonly DependencyPropertyKey OffsetPropertyKey = DependencyProperty.RegisterReadOnly(
"Offset", typeof(
double), typeof(
PropertyViewItem),
new FrameworkPropertyMetadata(0.0));
26 public static readonly DependencyProperty IncrementProperty = DependencyProperty.Register(
"Increment", typeof(
double), typeof(
PropertyViewItem),
new FrameworkPropertyMetadata(0.0, OnIncrementChanged));
28 public static readonly RoutedEvent ExpandedEvent = EventManager.RegisterRoutedEvent(
"Expanded", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(
PropertyViewItem));
30 public static readonly RoutedEvent CollapsedEvent = EventManager.RegisterRoutedEvent(
"Collapsed", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(
PropertyViewItem));
39 if (propertyView == null)
throw new ArgumentNullException(
"propertyView");
40 this.propertyView = propertyView;
41 PreviewMouseMove += propertyView.ItemMouseMove;
47 public IReadOnlyCollection<PropertyViewItem> Properties {
get {
return properties; } }
49 public bool IsExpanded {
get {
return (
bool)GetValue(IsExpandedProperty); } set { SetValue(IsExpandedProperty, value); } }
51 public bool CanBeHovered {
get {
return (
bool)GetValue(CanBeHoveredProperty); } set { SetValue(CanBeHoveredProperty, value); } }
53 public double Offset {
get {
return (
double)GetValue(OffsetPropertyKey.DependencyProperty); }
private set { SetValue(OffsetPropertyKey, value); } }
55 public double Increment {
get {
return (
double)GetValue(IncrementProperty); } set { SetValue(IncrementProperty, value); } }
57 public event RoutedEventHandler Expanded { add { AddHandler(ExpandedEvent, value); }
remove { RemoveHandler(ExpandedEvent, value); } }
59 public event RoutedEventHandler Collapsed { add { AddHandler(CollapsedEvent, value); }
remove { RemoveHandler(CollapsedEvent, value); } }
63 var item =
new PropertyViewItem(propertyView) { Offset = Offset + Increment };
74 if (!e.Handled && IsEnabled)
80 if (e.ClickCount % 2 == 0)
82 SetCurrentValue(IsExpandedProperty, !IsExpanded);
86 base.OnMouseLeftButtonDown(e);
91 base.PrepareContainerForItemOverride(element, item);
93 properties.Add(container);
101 properties.Remove(container);
102 base.ClearContainerForItemOverride(element, item);
121 private static void OnIsExpandedChanged(
DependencyObject d, DependencyPropertyChangedEventArgs e)
124 var isExpanded = (bool)e.NewValue;
140 private static void OnIncrementChanged(
DependencyObject d, DependencyPropertyChangedEventArgs e)
142 var item = (PropertyViewItem)d;
143 var delta = (double)e.NewValue - (
double)e.OldValue;
144 var subItems = item.FindVisualChildrenOfType<PropertyViewItem>();
145 foreach (var subItem
in subItems)
147 subItem.Offset += delta;
static readonly RoutedEvent PrepareItemEvent
Identifies the PreparePropertyItem event. This attached routed event may be raised by the PropertyGri...
override bool IsItemItsOwnContainerOverride(object item)
override DependencyObject GetContainerForItemOverride()
PropertyViewItem(PropertyView propertyView)
override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
virtual void OnExpanded(RoutedEventArgs e)
virtual void OnCollapsed(RoutedEventArgs e)
static readonly RoutedEvent ClearItemEvent
Identifies the ClearPropertyItem event. This attached routed event may be raised by the PropertyGrid ...
override void PrepareContainerForItemOverride(DependencyObject element, object item)
override void ClearContainerForItemOverride(DependencyObject element, object item)