/SharpTreeView/GeneralAdorner.cs

http://github.com/icsharpcode/ILSpy · C# · 81 lines · 56 code · 8 blank · 17 comment · 7 complexity · a4ba383c489f1b1ab591154cb00c1c46 MD5 · raw file

  1. // Copyright (c) 2020 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System.Windows.Documents;
  19. using System.Windows;
  20. using System.Windows.Media;
  21. namespace ICSharpCode.TreeView
  22. {
  23. public class GeneralAdorner : Adorner
  24. {
  25. public GeneralAdorner(UIElement target)
  26. : base(target)
  27. {
  28. }
  29. FrameworkElement child;
  30. public FrameworkElement Child
  31. {
  32. get
  33. {
  34. return child;
  35. }
  36. set
  37. {
  38. if (child != value) {
  39. RemoveVisualChild(child);
  40. RemoveLogicalChild(child);
  41. child = value;
  42. AddLogicalChild(value);
  43. AddVisualChild(value);
  44. InvalidateMeasure();
  45. }
  46. }
  47. }
  48. protected override int VisualChildrenCount
  49. {
  50. get { return child == null ? 0 : 1; }
  51. }
  52. protected override Visual GetVisualChild(int index)
  53. {
  54. return child;
  55. }
  56. protected override Size MeasureOverride(Size constraint)
  57. {
  58. if (child != null) {
  59. child.Measure(constraint);
  60. return child.DesiredSize;
  61. }
  62. return new Size();
  63. }
  64. protected override Size ArrangeOverride(Size finalSize)
  65. {
  66. if (child != null) {
  67. child.Arrange(new Rect(finalSize));
  68. return finalSize;
  69. }
  70. return new Size();
  71. }
  72. }
  73. }