AnchorablePaneTabPanel.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.Controls;
  15. using System.Windows;
  16. using Xceed.Wpf.AvalonDock.Layout;
  17. namespace Xceed.Wpf.AvalonDock.Controls
  18. {
  19. public class AnchorablePaneTabPanel : Panel
  20. {
  21. public AnchorablePaneTabPanel()
  22. {
  23. FlowDirection = System.Windows.FlowDirection.LeftToRight;
  24. }
  25. protected override Size MeasureOverride(Size availableSize)
  26. {
  27. double totWidth = 0;
  28. double maxHeight = 0;
  29. var visibleChildren = Children.Cast<UIElement>().Where(ch => ch.Visibility != System.Windows.Visibility.Collapsed);
  30. foreach (FrameworkElement child in visibleChildren)
  31. {
  32. child.Measure(new Size(double.PositiveInfinity, availableSize.Height));
  33. totWidth += child.DesiredSize.Width;
  34. maxHeight = Math.Max(maxHeight, child.DesiredSize.Height);
  35. }
  36. if (totWidth > availableSize.Width)
  37. {
  38. double childFinalDesideredWidth = availableSize.Width / visibleChildren.Count();
  39. foreach (FrameworkElement child in visibleChildren)
  40. {
  41. child.Measure(new Size(childFinalDesideredWidth, availableSize.Height));
  42. }
  43. }
  44. return new Size(Math.Min(availableSize.Width, totWidth), maxHeight);
  45. }
  46. protected override Size ArrangeOverride(Size finalSize)
  47. {
  48. var visibleChildren = Children.Cast<UIElement>().Where(ch => ch.Visibility != System.Windows.Visibility.Collapsed);
  49. double finalWidth = finalSize.Width;
  50. double desideredWidth = visibleChildren.Sum(ch => ch.DesiredSize.Width);
  51. double offsetX = 0.0;
  52. if (finalWidth > desideredWidth)
  53. {
  54. foreach (FrameworkElement child in visibleChildren)
  55. {
  56. double childFinalWidth = child.DesiredSize.Width ;
  57. child.Arrange(new Rect(offsetX, 0, childFinalWidth, finalSize.Height));
  58. offsetX += childFinalWidth;
  59. }
  60. }
  61. else
  62. {
  63. double childFinalWidth = finalWidth / visibleChildren.Count();
  64. foreach (FrameworkElement child in visibleChildren)
  65. {
  66. child.Arrange(new Rect(offsetX, 0, childFinalWidth, finalSize.Height));
  67. offsetX += childFinalWidth;
  68. }
  69. }
  70. return finalSize;
  71. }
  72. protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
  73. {
  74. if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed &&
  75. LayoutAnchorableTabItem.IsDraggingItem())
  76. {
  77. var contentModel = LayoutAnchorableTabItem.GetDraggingItem().Model as LayoutAnchorable;
  78. var manager = contentModel.Root.Manager;
  79. LayoutAnchorableTabItem.ResetDraggingItem();
  80. manager.StartDraggingFloatingWindowForContent(contentModel);
  81. }
  82. base.OnMouseLeave(e);
  83. }
  84. }
  85. }