LayoutDocumentControl.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Input;
  13. using Xceed.Wpf.AvalonDock.Layout;
  14. namespace Xceed.Wpf.AvalonDock.Controls
  15. {
  16. public class LayoutDocumentControl : Control
  17. {
  18. static LayoutDocumentControl()
  19. {
  20. DefaultStyleKeyProperty.OverrideMetadata(typeof(LayoutDocumentControl), new FrameworkPropertyMetadata(typeof(LayoutDocumentControl)));
  21. FocusableProperty.OverrideMetadata(typeof(LayoutDocumentControl), new FrameworkPropertyMetadata(false));
  22. }
  23. public LayoutDocumentControl()
  24. {
  25. //SetBinding(FlowDirectionProperty, new Binding("Model.Root.Manager.FlowDirection") { Source = this });
  26. }
  27. #region Model
  28. /// <summary>
  29. /// Model Dependency Property
  30. /// </summary>
  31. public static readonly DependencyProperty ModelProperty =
  32. DependencyProperty.Register("Model", typeof(LayoutContent), typeof(LayoutDocumentControl),
  33. new FrameworkPropertyMetadata((LayoutContent)null,
  34. new PropertyChangedCallback(OnModelChanged)));
  35. /// <summary>
  36. /// Gets or sets the Model property. This dependency property
  37. /// indicates the model attached to this view.
  38. /// </summary>
  39. public LayoutContent Model
  40. {
  41. get { return (LayoutContent)GetValue(ModelProperty); }
  42. set { SetValue(ModelProperty, value); }
  43. }
  44. /// <summary>
  45. /// Handles changes to the Model property.
  46. /// </summary>
  47. private static void OnModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  48. {
  49. ((LayoutDocumentControl)d).OnModelChanged(e);
  50. }
  51. /// <summary>
  52. /// Provides derived classes an opportunity to handle changes to the Model property.
  53. /// </summary>
  54. protected virtual void OnModelChanged(DependencyPropertyChangedEventArgs e)
  55. {
  56. if (Model != null)
  57. SetLayoutItem(Model.Root.Manager.GetLayoutItemFromModel(Model));
  58. else
  59. SetLayoutItem(null);
  60. }
  61. #endregion
  62. #region LayoutItem
  63. /// <summary>
  64. /// LayoutItem Read-Only Dependency Property
  65. /// </summary>
  66. private static readonly DependencyPropertyKey LayoutItemPropertyKey
  67. = DependencyProperty.RegisterReadOnly("LayoutItem", typeof(LayoutItem), typeof(LayoutDocumentControl),
  68. new FrameworkPropertyMetadata((LayoutItem)null));
  69. public static readonly DependencyProperty LayoutItemProperty
  70. = LayoutItemPropertyKey.DependencyProperty;
  71. /// <summary>
  72. /// Gets the LayoutItem property. This dependency property
  73. /// indicates the LayoutItem attached to this tag item.
  74. /// </summary>
  75. public LayoutItem LayoutItem
  76. {
  77. get { return (LayoutItem)GetValue(LayoutItemProperty); }
  78. }
  79. /// <summary>
  80. /// Provides a secure method for setting the LayoutItem property.
  81. /// This dependency property indicates the LayoutItem attached to this tag item.
  82. /// </summary>
  83. /// <param name="value">The new value for the property.</param>
  84. protected void SetLayoutItem(LayoutItem value)
  85. {
  86. SetValue(LayoutItemPropertyKey, value);
  87. }
  88. #endregion
  89. //protected override void OnPreviewGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e)
  90. //{
  91. // if (Model != null)
  92. // Model.IsActive = true;
  93. // base.OnPreviewGotKeyboardFocus(e);
  94. //}
  95. //Daniel-使用PreviewMouseLeftButtonDown代替PreviewGotKeyboardFocus事件,单击时激活窗口
  96. protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
  97. {
  98. if (!e.Handled && Model != null)
  99. {
  100. Model.IsActive = true;
  101. }
  102. base.OnPreviewMouseLeftButtonUp(e);
  103. }
  104. }
  105. }