LayoutAnchorableControl.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*************************************************************************************
  2. Extended WPF Toolkit
  3. Copyright (C) 2007-2013 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features, controls, and fast professional support,
  7. pick up the Plus Edition at http://xceed.com/wpf_toolkit
  8. Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
  9. ***********************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Data;
  17. using System.Windows.Documents;
  18. using System.Windows.Input;
  19. using System.Windows.Media;
  20. using System.Windows.Media.Imaging;
  21. using System.Windows.Navigation;
  22. using System.Windows.Shapes;
  23. using Xceed.Wpf.AvalonDock.Layout;
  24. namespace Xceed.Wpf.AvalonDock.Controls
  25. {
  26. public class LayoutAnchorableControl : Control
  27. {
  28. static LayoutAnchorableControl()
  29. {
  30. DefaultStyleKeyProperty.OverrideMetadata(typeof(LayoutAnchorableControl), new FrameworkPropertyMetadata(typeof(LayoutAnchorableControl)));
  31. FocusableProperty.OverrideMetadata(typeof(LayoutAnchorableControl), new FrameworkPropertyMetadata(false));
  32. }
  33. public LayoutAnchorableControl()
  34. {
  35. //SetBinding(FlowDirectionProperty, new Binding("Model.Root.Manager.FlowDirection") { Source = this });
  36. }
  37. #region Model
  38. /// <summary>
  39. /// Model Dependency Property
  40. /// </summary>
  41. public static readonly DependencyProperty ModelProperty =
  42. DependencyProperty.Register("Model", typeof(LayoutAnchorable), typeof(LayoutAnchorableControl),
  43. new FrameworkPropertyMetadata((LayoutAnchorable)null,
  44. new PropertyChangedCallback(OnModelChanged)));
  45. /// <summary>
  46. /// Gets or sets the Model property. This dependency property
  47. /// indicates the model attached to this view.
  48. /// </summary>
  49. public LayoutAnchorable Model
  50. {
  51. get { return (LayoutAnchorable)GetValue(ModelProperty); }
  52. set { SetValue(ModelProperty, value); }
  53. }
  54. /// <summary>
  55. /// Handles changes to the Model property.
  56. /// </summary>
  57. private static void OnModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  58. {
  59. ((LayoutAnchorableControl)d).OnModelChanged(e);
  60. }
  61. /// <summary>
  62. /// Provides derived classes an opportunity to handle changes to the Model property.
  63. /// </summary>
  64. protected virtual void OnModelChanged(DependencyPropertyChangedEventArgs e)
  65. {
  66. if (Model != null)
  67. SetLayoutItem(Model.Root.Manager.GetLayoutItemFromModel(Model));
  68. else
  69. SetLayoutItem(null);
  70. }
  71. #endregion
  72. #region LayoutItem
  73. /// <summary>
  74. /// LayoutItem Read-Only Dependency Property
  75. /// </summary>
  76. private static readonly DependencyPropertyKey LayoutItemPropertyKey
  77. = DependencyProperty.RegisterReadOnly("LayoutItem", typeof(LayoutItem), typeof(LayoutAnchorableControl),
  78. new FrameworkPropertyMetadata((LayoutItem)null));
  79. public static readonly DependencyProperty LayoutItemProperty
  80. = LayoutItemPropertyKey.DependencyProperty;
  81. /// <summary>
  82. /// Gets the LayoutItem property. This dependency property
  83. /// indicates the LayoutItem attached to this tag item.
  84. /// </summary>
  85. public LayoutItem LayoutItem
  86. {
  87. get { return (LayoutItem)GetValue(LayoutItemProperty); }
  88. }
  89. /// <summary>
  90. /// Provides a secure method for setting the LayoutItem property.
  91. /// This dependency property indicates the LayoutItem attached to this tag item.
  92. /// </summary>
  93. /// <param name="value">The new value for the property.</param>
  94. protected void SetLayoutItem(LayoutItem value)
  95. {
  96. SetValue(LayoutItemPropertyKey, value);
  97. }
  98. #endregion
  99. protected override void OnGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e)
  100. {
  101. if (Model != null)
  102. Model.IsActive = true;
  103. base.OnGotKeyboardFocus(e);
  104. }
  105. }
  106. }