Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PropertyView.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 
4 using System;
5 using System.Collections.Generic;
6 using System.Windows;
7 using System.Windows.Controls;
8 using System.Windows.Input;
9 
10 using SiliconStudio.Presentation.Collections;
11 
12 namespace SiliconStudio.Presentation.Controls
13 {
14  public class PropertyView : ItemsControl
15  {
16  private readonly ObservableList<PropertyViewItem> properties = new ObservableList<PropertyViewItem>();
17 
18  /// <summary>
19  /// Identifies the <see cref="HoveredItem"/> dependency property.
20  /// </summary>
21  public static readonly DependencyPropertyKey HoveredItemPropertyKey = DependencyProperty.RegisterReadOnly("HoveredItem", typeof(PropertyViewItem), typeof(PropertyView), new PropertyMetadata(null));
22 
23  /// <summary>
24  /// Identifies the PreparePropertyItem event.
25  /// This attached routed event may be raised by the PropertyGrid itself or by a PropertyItemBase containing sub-items.
26  /// </summary>
27  public static readonly RoutedEvent PrepareItemEvent = EventManager.RegisterRoutedEvent("PrepareItem", RoutingStrategy.Bubble, typeof(EventHandler<PropertyViewItemEventArgs>), typeof(PropertyView));
28 
29  /// <summary>
30  /// Identifies the ClearPropertyItem event.
31  /// This attached routed event may be raised by the PropertyGrid itself or by a
32  /// PropertyItemBase containing sub items.
33  /// </summary>
34  public static readonly RoutedEvent ClearItemEvent = EventManager.RegisterRoutedEvent("ClearItem", RoutingStrategy.Bubble, typeof(EventHandler<PropertyViewItemEventArgs>), typeof(PropertyView));
35 
36  static PropertyView()
37  {
38  DefaultStyleKeyProperty.OverrideMetadata(typeof(PropertyView), new FrameworkPropertyMetadata(typeof(PropertyView)));
39  }
40 
41  public IReadOnlyCollection<PropertyViewItem> Properties { get { return properties; } }
42 
43  /// <summary>
44  /// Gets the trimmed text to display when the control does not have the focus, depending of the value of the <see cref="TextTrimming"/> property.
45  /// </summary>
46  public PropertyViewItem HoveredItem { get { return (PropertyViewItem)GetValue(HoveredItemPropertyKey.DependencyProperty); } private set { SetValue(HoveredItemPropertyKey, value); } }
47 
48  /// <summary>
49  /// This event is raised when a property item is about to be displayed in the PropertyGrid.
50  /// This allow the user to customize the property item just before it is displayed.
51  /// </summary>
52  public event EventHandler<PropertyViewItemEventArgs> PrepareItem { add { AddHandler(PrepareItemEvent, value); } remove { RemoveHandler(PrepareItemEvent, value); } }
53 
54  /// <summary>
55  /// This event is raised when an property item is about to be remove from the display in the PropertyGrid
56  /// This allow the user to remove any attached handler in the PreparePropertyItem event.
57  /// </summary>
58  public event EventHandler<PropertyViewItemEventArgs> ClearItem { add { AddHandler(ClearItemEvent, value); } remove { RemoveHandler(ClearItemEvent, value); } }
59 
60  internal void ItemMouseMove(object sender, MouseEventArgs e)
61  {
62  var item = sender as PropertyViewItem;
63  if (item != null && item.CanBeHovered)
64  {
65  HoveredItem = item;
66  }
67  }
68 
69  protected override void OnMouseLeave(MouseEventArgs e)
70  {
71  base.OnMouseLeave(e);
72  HoveredItem = null;
73  }
74 
76  {
77  return new PropertyViewItem(this);
78  }
79 
80  protected override bool IsItemItsOwnContainerOverride(object item)
81  {
82  return item is PropertyViewItem;
83  }
84 
85  protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
86  {
87  base.PrepareContainerForItemOverride(element, item);
88  var container = (PropertyViewItem)element;
89  properties.Add(container);
90  RaiseEvent(new PropertyViewItemEventArgs(PrepareItemEvent, this, container, item));
91  }
92 
93  protected override void ClearContainerForItemOverride(DependencyObject element, object item)
94  {
95  var container = (PropertyViewItem)element;
96  RaiseEvent(new PropertyViewItemEventArgs(ClearItemEvent, this, (PropertyViewItem)element, item));
97  properties.Remove(container);
98  base.ClearContainerForItemOverride(element, item);
99  }
100 
101  //protected override AutomationPeer OnCreateAutomationPeer()
102  //{
103  // return (AutomationPeer)new TreeViewAutomationPeer(this);
104  //}
105  }
106 }
override DependencyObject GetContainerForItemOverride()
Definition: PropertyView.cs:75
override void PrepareContainerForItemOverride(DependencyObject element, object item)
Definition: PropertyView.cs:85
override void ClearContainerForItemOverride(DependencyObject element, object item)
Definition: PropertyView.cs:93
override void OnMouseLeave(MouseEventArgs e)
Definition: PropertyView.cs:69
override bool IsItemItsOwnContainerOverride(object item)
Definition: PropertyView.cs:80