LayoutAnchorablePaneControl.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.Collections.ObjectModel;
  15. using System.Windows.Controls;
  16. using System.Windows;
  17. using System.Windows.Data;
  18. using Xceed.Wpf.AvalonDock.Layout;
  19. namespace Xceed.Wpf.AvalonDock.Controls
  20. {
  21. public class LayoutAnchorablePaneControl : TabControl, ILayoutControl//, ILogicalChildrenContainer
  22. {
  23. static LayoutAnchorablePaneControl()
  24. {
  25. FocusableProperty.OverrideMetadata(typeof(LayoutAnchorablePaneControl), new FrameworkPropertyMetadata(false));
  26. }
  27. public LayoutAnchorablePaneControl(LayoutAnchorablePane model)
  28. {
  29. if (model == null)
  30. throw new ArgumentNullException("model");
  31. _model = model;
  32. SetBinding(ItemsSourceProperty, new Binding("Model.Children") { Source = this });
  33. SetBinding(FlowDirectionProperty, new Binding("Model.Root.Manager.FlowDirection") { Source = this });
  34. this.LayoutUpdated += new EventHandler(OnLayoutUpdated);
  35. }
  36. void OnLayoutUpdated(object sender, EventArgs e)
  37. {
  38. var modelWithAtcualSize = _model as ILayoutPositionableElementWithActualSize;
  39. modelWithAtcualSize.ActualWidth = ActualWidth;
  40. modelWithAtcualSize.ActualHeight = ActualHeight;
  41. }
  42. LayoutAnchorablePane _model;
  43. public ILayoutElement Model
  44. {
  45. get { return _model; }
  46. }
  47. protected override void OnGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e)
  48. {
  49. _model.SelectedContent.IsActive = true;
  50. base.OnGotKeyboardFocus(e);
  51. }
  52. protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
  53. {
  54. base.OnMouseLeftButtonDown(e);
  55. if (!e.Handled && _model.SelectedContent != null)
  56. _model.SelectedContent.IsActive = true;
  57. }
  58. protected override void OnMouseRightButtonDown(System.Windows.Input.MouseButtonEventArgs e)
  59. {
  60. base.OnMouseRightButtonDown(e);
  61. if (!e.Handled && _model.SelectedContent != null)
  62. _model.SelectedContent.IsActive = true;
  63. }
  64. }
  65. }