|
| 1 | +// Copyright (c) Files Community |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +namespace DevWinUI; |
| 5 | + |
| 6 | +public sealed partial class SidebarItem : Control |
| 7 | +{ |
| 8 | + public SidebarView? Owner |
| 9 | + { |
| 10 | + get { return (SidebarView?)GetValue(OwnerProperty); } |
| 11 | + set { SetValue(OwnerProperty, value); } |
| 12 | + } |
| 13 | + public static readonly DependencyProperty OwnerProperty = |
| 14 | + DependencyProperty.Register(nameof(Owner), typeof(SidebarView), typeof(SidebarItem), new PropertyMetadata(null)); |
| 15 | + |
| 16 | + public bool IsSelected |
| 17 | + { |
| 18 | + get { return (bool)GetValue(IsSelectedProperty); } |
| 19 | + set { SetValue(IsSelectedProperty, value); } |
| 20 | + } |
| 21 | + public static readonly DependencyProperty IsSelectedProperty = |
| 22 | + DependencyProperty.Register(nameof(IsSelected), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false, OnPropertyChanged)); |
| 23 | + |
| 24 | + public bool IsExpanded |
| 25 | + { |
| 26 | + get { return (bool)GetValue(IsExpandedProperty); } |
| 27 | + set { SetValue(IsExpandedProperty, value); } |
| 28 | + } |
| 29 | + public static readonly DependencyProperty IsExpandedProperty = |
| 30 | + DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(SidebarItem), new PropertyMetadata(true, OnPropertyChanged)); |
| 31 | + |
| 32 | + public bool IsInFlyout |
| 33 | + { |
| 34 | + get { return (bool)GetValue(IsInFlyoutProperty); } |
| 35 | + set { SetValue(IsInFlyoutProperty, value); } |
| 36 | + } |
| 37 | + public static readonly DependencyProperty IsInFlyoutProperty = |
| 38 | + DependencyProperty.Register(nameof(IsInFlyout), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false)); |
| 39 | + |
| 40 | + public double ChildrenPresenterHeight |
| 41 | + { |
| 42 | + get { return (double)GetValue(ChildrenPresenterHeightProperty); } |
| 43 | + set { SetValue(ChildrenPresenterHeightProperty, value); } |
| 44 | + } |
| 45 | + // Using 30 as a default in case something goes wrong |
| 46 | + public static readonly DependencyProperty ChildrenPresenterHeightProperty = |
| 47 | + DependencyProperty.Register(nameof(ChildrenPresenterHeight), typeof(double), typeof(SidebarItem), new PropertyMetadata(30d)); |
| 48 | + |
| 49 | + public ISidebarItemModel? Item |
| 50 | + { |
| 51 | + get { return (ISidebarItemModel)GetValue(ItemProperty); } |
| 52 | + set { SetValue(ItemProperty, value); } |
| 53 | + } |
| 54 | + public static readonly DependencyProperty ItemProperty = |
| 55 | + DependencyProperty.Register(nameof(Item), typeof(ISidebarItemModel), typeof(SidebarItem), new PropertyMetadata(null)); |
| 56 | + |
| 57 | + public bool UseReorderDrop |
| 58 | + { |
| 59 | + get { return (bool)GetValue(UseReorderDropProperty); } |
| 60 | + set { SetValue(UseReorderDropProperty, value); } |
| 61 | + } |
| 62 | + public static readonly DependencyProperty UseReorderDropProperty = |
| 63 | + DependencyProperty.Register(nameof(UseReorderDrop), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false)); |
| 64 | + |
| 65 | + public FrameworkElement? Icon |
| 66 | + { |
| 67 | + get { return (FrameworkElement?)GetValue(IconProperty); } |
| 68 | + set { SetValue(IconProperty, value); } |
| 69 | + } |
| 70 | + public static readonly DependencyProperty IconProperty = |
| 71 | + DependencyProperty.Register(nameof(Icon), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null)); |
| 72 | + |
| 73 | + public FrameworkElement? Decorator |
| 74 | + { |
| 75 | + get { return (FrameworkElement?)GetValue(DecoratorProperty); } |
| 76 | + set { SetValue(DecoratorProperty, value); } |
| 77 | + } |
| 78 | + public static readonly DependencyProperty DecoratorProperty = |
| 79 | + DependencyProperty.Register(nameof(Decorator), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null)); |
| 80 | + |
| 81 | + public SidebarDisplayMode DisplayMode |
| 82 | + { |
| 83 | + get { return (SidebarDisplayMode)GetValue(DisplayModeProperty); } |
| 84 | + set { SetValue(DisplayModeProperty, value); } |
| 85 | + } |
| 86 | + public static readonly DependencyProperty DisplayModeProperty = |
| 87 | + DependencyProperty.Register(nameof(DisplayMode), typeof(SidebarDisplayMode), typeof(SidebarItem), new PropertyMetadata(SidebarDisplayMode.Expanded, OnPropertyChanged)); |
| 88 | + |
| 89 | + public static void SetTemplateRoot(DependencyObject target, FrameworkElement value) |
| 90 | + { |
| 91 | + target.SetValue(TemplateRootProperty, value); |
| 92 | + } |
| 93 | + public static FrameworkElement GetTemplateRoot(DependencyObject target) |
| 94 | + { |
| 95 | + return (FrameworkElement)target.GetValue(TemplateRootProperty); |
| 96 | + } |
| 97 | + public static readonly DependencyProperty TemplateRootProperty = |
| 98 | + DependencyProperty.Register("TemplateRoot", typeof(FrameworkElement), typeof(FrameworkElement), new PropertyMetadata(null)); |
| 99 | + |
| 100 | + public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
| 101 | + { |
| 102 | + if (sender is not SidebarItem item) return; |
| 103 | + if (e.Property == DisplayModeProperty) |
| 104 | + { |
| 105 | + item.SidebarDisplayModeChanged((SidebarDisplayMode)e.OldValue); |
| 106 | + } |
| 107 | + else if (e.Property == IsSelectedProperty) |
| 108 | + { |
| 109 | + item.UpdateSelectionState(); |
| 110 | + } |
| 111 | + else if (e.Property == IsExpandedProperty) |
| 112 | + { |
| 113 | + item.UpdateExpansionState(); |
| 114 | + } |
| 115 | + else if (e.Property == ItemProperty) |
| 116 | + { |
| 117 | + item.HandleItemChange(); |
| 118 | + } |
| 119 | + } |
| 120 | +} |
0 commit comments