|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +namespace CommunityToolkit.App.Shared.Controls; |
| 6 | + |
| 7 | +public partial class TitleBar : Control |
| 8 | +{ |
| 9 | + /// <summary> |
| 10 | + /// The backing <see cref="DependencyProperty"/> for the <see cref="Icon"/> property. |
| 11 | + /// </summary> |
| 12 | + public static readonly DependencyProperty IconProperty = DependencyProperty.Register(nameof(Icon), typeof(IconElement), typeof(TitleBar), new PropertyMetadata(null, IconChanged)); |
| 13 | + |
| 14 | + /// <summary> |
| 15 | + /// The backing <see cref="DependencyProperty"/> for the <see cref="Title"/> property. |
| 16 | + /// </summary> |
| 17 | + public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(TitleBar), new PropertyMetadata(default(string))); |
| 18 | + |
| 19 | + /// <summary> |
| 20 | + /// The backing <see cref="DependencyProperty"/> for the <see cref="Subtitle"/> property. |
| 21 | + /// </summary> |
| 22 | + public static readonly DependencyProperty SubtitleProperty = DependencyProperty.Register(nameof(Subtitle), typeof(string), typeof(TitleBar), new PropertyMetadata(default(string))); |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// The backing <see cref="DependencyProperty"/> for the <see cref="Content"/> property. |
| 26 | + /// </summary> |
| 27 | + public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(nameof(Content), typeof(object), typeof(TitleBar), new PropertyMetadata(null, ContentChanged)); |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// The backing <see cref="DependencyProperty"/> for the <see cref="Footer"/> property. |
| 31 | + /// </summary> |
| 32 | + public static readonly DependencyProperty FooterProperty = DependencyProperty.Register(nameof(Footer), typeof(object), typeof(TitleBar), new PropertyMetadata(null, FooterChanged)); |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// The backing <see cref="DependencyProperty"/> for the <see cref="IsBackButtonVisible"/> property. |
| 36 | + /// </summary> |
| 37 | + public static readonly DependencyProperty IsBackButtonVisibleProperty = DependencyProperty.Register(nameof(IsBackButtonVisible), typeof(bool), typeof(TitleBar), new PropertyMetadata(false, IsBackButtonVisibleChanged)); |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// The backing <see cref="DependencyProperty"/> for the <see cref="IsPaneButtonVisible"/> property. |
| 41 | + /// </summary> |
| 42 | + public static readonly DependencyProperty IsPaneButtonVisibleProperty = DependencyProperty.Register(nameof(IsPaneButtonVisible), typeof(bool), typeof(TitleBar), new PropertyMetadata(false, IsPaneButtonVisibleChanged)); |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// The backing <see cref="DependencyProperty"/> for the <see cref="Display"/> property. |
| 46 | + /// </summary> |
| 47 | + public static readonly DependencyProperty DisplayModeProperty = DependencyProperty.Register(nameof(DisplayMode), typeof(DisplayMode), typeof(TitleBar), new PropertyMetadata(DisplayMode.Standard, DisplayModeChanged)); |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// The backing <see cref="DependencyProperty"/> for the <see cref="CompactStateBreakpoint |
| 51 | + /// "/> property. |
| 52 | + /// </summary> |
| 53 | + public static readonly DependencyProperty CompactStateBreakpointProperty = DependencyProperty.Register(nameof(CompactStateBreakpoint), typeof(int), typeof(TitleBar), new PropertyMetadata(850)); |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// The backing <see cref="DependencyProperty"/> for the <see cref="AutoConfigureCustomTitleBar"/> property. |
| 57 | + /// </summary> |
| 58 | + public static readonly DependencyProperty AutoConfigureCustomTitleBarProperty = DependencyProperty.Register(nameof(AutoConfigureCustomTitleBar), typeof(bool), typeof(TitleBar), new PropertyMetadata(true, AutoConfigureCustomTitleBarChanged)); |
| 59 | + |
| 60 | +#if WINAPPSDK |
| 61 | + /// <summary> |
| 62 | + /// The backing <see cref="DependencyProperty"/> for the <see cref="Window"/> property. |
| 63 | + /// </summary> |
| 64 | + public static readonly DependencyProperty WindowProperty = DependencyProperty.Register(nameof(Window), typeof(Window), typeof(TitleBar), new PropertyMetadata(null)); |
| 65 | +#endif |
| 66 | + |
| 67 | + /// <summary> |
| 68 | + /// The event that gets fired when the back button is clicked |
| 69 | + /// </summary> |
| 70 | + public event EventHandler<RoutedEventArgs>? BackButtonClick; |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// The event that gets fired when the pane toggle button is clicked |
| 74 | + /// </summary> |
| 75 | + public event EventHandler<RoutedEventArgs>? PaneButtonClick; |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// Gets or sets the Icon |
| 79 | + /// </summary> |
| 80 | + public IconElement Icon |
| 81 | + { |
| 82 | + get => (IconElement)GetValue(IconProperty); |
| 83 | + set => SetValue(IconProperty, value); |
| 84 | + } |
| 85 | + |
| 86 | + /// <summary> |
| 87 | + /// Gets or sets the Title |
| 88 | + /// </summary> |
| 89 | + public string Title |
| 90 | + { |
| 91 | + get => (string)GetValue(TitleProperty); |
| 92 | + set => SetValue(TitleProperty, value); |
| 93 | + } |
| 94 | + |
| 95 | + /// <summary> |
| 96 | + /// Gets or sets the Subtitle |
| 97 | + /// </summary> |
| 98 | + public string Subtitle |
| 99 | + { |
| 100 | + get => (string)GetValue(SubtitleProperty); |
| 101 | + set => SetValue(SubtitleProperty, value); |
| 102 | + } |
| 103 | + |
| 104 | + /// <summary> |
| 105 | + /// Gets or sets the content shown at the center of the TitleBar. When setting this, using DisplayMode=Tall is recommended. |
| 106 | + /// </summary> |
| 107 | + public object Content |
| 108 | + { |
| 109 | + get => (object)GetValue(ContentProperty); |
| 110 | + set => SetValue(ContentProperty, value); |
| 111 | + } |
| 112 | + |
| 113 | + /// <summary> |
| 114 | + /// Gets or sets the content shown at the right of the TitleBar, next to the caption buttons. When setting this, using DisplayMode=Tall is recommended. |
| 115 | + /// </summary> |
| 116 | + public object Footer |
| 117 | + { |
| 118 | + get => (object)GetValue(FooterProperty); |
| 119 | + set => SetValue(FooterProperty, value); |
| 120 | + } |
| 121 | + |
| 122 | + /// <summary> |
| 123 | + /// Gets or sets DisplayMode. Compact is default (32px), Tall is recommended when setting the Content or Footer. |
| 124 | + /// </summary> |
| 125 | + public DisplayMode DisplayMode |
| 126 | + { |
| 127 | + get => (DisplayMode)GetValue(DisplayModeProperty); |
| 128 | + set => SetValue(DisplayModeProperty, value); |
| 129 | + } |
| 130 | + |
| 131 | + /// <summary> |
| 132 | + /// Gets or sets the visibility of the back button. |
| 133 | + /// </summary> |
| 134 | + public bool IsBackButtonVisible |
| 135 | + { |
| 136 | + get => (bool)GetValue(IsBackButtonVisibleProperty); |
| 137 | + set => SetValue(IsBackButtonVisibleProperty, value); |
| 138 | + } |
| 139 | + |
| 140 | + /// <summary> |
| 141 | + /// Gets or sets the visibility of the pane toggle button. |
| 142 | + /// </summary> |
| 143 | + public bool IsPaneButtonVisible |
| 144 | + { |
| 145 | + get => (bool)GetValue(IsPaneButtonVisibleProperty); |
| 146 | + set => SetValue(IsPaneButtonVisibleProperty, value); |
| 147 | + } |
| 148 | + |
| 149 | + /// <summary> |
| 150 | + /// Gets or sets the breakpoint of when the compact state is triggered. |
| 151 | + /// </summary> |
| 152 | + public int CompactStateBreakpoint |
| 153 | + { |
| 154 | + get => (int)GetValue(CompactStateBreakpointProperty); |
| 155 | + set => SetValue(CompactStateBreakpointProperty, value); |
| 156 | + } |
| 157 | + |
| 158 | + /// <summary> |
| 159 | + /// Gets or sets if the TitleBar should auto configure ExtendContentIntoTitleBar and CaptionButtion background colors. |
| 160 | + /// </summary> |
| 161 | + public bool AutoConfigureCustomTitleBar |
| 162 | + { |
| 163 | + get => (bool)GetValue(AutoConfigureCustomTitleBarProperty); |
| 164 | + set => SetValue(AutoConfigureCustomTitleBarProperty, value); |
| 165 | + } |
| 166 | + |
| 167 | +#if WINAPPSDK |
| 168 | + /// <summary> |
| 169 | + /// Gets or sets the window the TitleBar should configure (WASDK only). |
| 170 | + /// </summary> |
| 171 | + public Window Window |
| 172 | + { |
| 173 | + get => (Window)GetValue(WindowProperty); |
| 174 | + set => SetValue(WindowProperty, value); |
| 175 | + } |
| 176 | +#endif |
| 177 | + |
| 178 | + private static void IsBackButtonVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 179 | + { |
| 180 | + ((TitleBar)d).Update(); |
| 181 | + } |
| 182 | + |
| 183 | + private static void IsPaneButtonVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 184 | + { |
| 185 | + ((TitleBar)d).Update(); |
| 186 | + } |
| 187 | + |
| 188 | + private static void DisplayModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 189 | + { |
| 190 | + ((TitleBar)d).Update(); |
| 191 | + } |
| 192 | + |
| 193 | + private static void ContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 194 | + { |
| 195 | + ((TitleBar)d).Update(); |
| 196 | + } |
| 197 | + |
| 198 | + private static void FooterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 199 | + { |
| 200 | + ((TitleBar)d).Update(); |
| 201 | + } |
| 202 | + |
| 203 | + private static void IconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 204 | + { |
| 205 | + ((TitleBar)d).Update(); |
| 206 | + } |
| 207 | + |
| 208 | + private static void AutoConfigureCustomTitleBarChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 209 | + { |
| 210 | + if (((TitleBar)d).AutoConfigureCustomTitleBar) |
| 211 | + { |
| 212 | + ((TitleBar)d).Configure(); |
| 213 | + } |
| 214 | + else |
| 215 | + { |
| 216 | + ((TitleBar)d).Reset(); |
| 217 | + } |
| 218 | + } |
| 219 | +} |
| 220 | + |
| 221 | +public enum DisplayMode |
| 222 | +{ |
| 223 | + Standard, |
| 224 | + Tall |
| 225 | +} |
0 commit comments