Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gallery design improvements #88

Merged
merged 10 commits into from
Jul 19, 2023
Prev Previous commit
Next Next commit
Refactoring
  • Loading branch information
niels9001 committed Jul 4, 2023
commit 83207c79438bf21a7dc9a1a3aa8dc53341a1d976
125 changes: 111 additions & 14 deletions CommunityToolkit.App.Shared/Controls/TitleBar/TitleBar.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,83 +6,168 @@ namespace CommunityToolkit.App.Shared.Controls;

public partial class TitleBar : Control
{
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(nameof(Icon), typeof(ImageSource), typeof(TitleBar), new PropertyMetadata(default(ImageSource)));

/// <summary>
/// The backing <see cref="DependencyProperty"/> for the <see cref="Icon"/> property.
/// </summary>
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(nameof(Icon), typeof(IconElement), typeof(TitleBar), new PropertyMetadata(null, IconChanged));

/// <summary>
/// The backing <see cref="DependencyProperty"/> for the <see cref="Title"/> property.
/// </summary>
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(TitleBar), new PropertyMetadata(default(string)));

/// <summary>
/// The backing <see cref="DependencyProperty"/> for the <see cref="Subtitle"/> property.
/// </summary>
public static readonly DependencyProperty SubtitleProperty = DependencyProperty.Register(nameof(Subtitle), typeof(string), typeof(TitleBar), new PropertyMetadata(default(string)));

/// <summary>
/// The backing <see cref="DependencyProperty"/> for the <see cref="Content"/> property.
/// </summary>
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(nameof(Content), typeof(object), typeof(TitleBar), new PropertyMetadata(null));

/// <summary>
/// The backing <see cref="DependencyProperty"/> for the <see cref="Footer"/> property.
/// </summary>
public static readonly DependencyProperty FooterProperty = DependencyProperty.Register(nameof(Footer), typeof(object), typeof(TitleBar), new PropertyMetadata(null));

/// <summary>
/// The backing <see cref="DependencyProperty"/> for the <see cref="IsBackButtonVisible"/> property.
/// </summary>
public static readonly DependencyProperty IsBackButtonVisibleProperty = DependencyProperty.Register(nameof(IsBackButtonVisible), typeof(bool), typeof(TitleBar), new PropertyMetadata(false, IsBackButtonVisibleChanged));

/// <summary>
/// The backing <see cref="DependencyProperty"/> for the <see cref="IsPaneButtonVisible"/> property.
/// </summary>
public static readonly DependencyProperty IsPaneButtonVisibleProperty = DependencyProperty.Register(nameof(IsPaneButtonVisible), typeof(bool), typeof(TitleBar), new PropertyMetadata(false, IsPaneButtonVisibleChanged));

public static readonly DependencyProperty ConfigureTitleBarProperty = DependencyProperty.Register(nameof(ConfigureTitleBar), typeof(bool), typeof(TitleBar), new PropertyMetadata(true, ConfigureTitleBarChanged));

/// <summary>
/// The backing <see cref="DependencyProperty"/> for the <see cref="Display"/> property.
/// </summary>
public static readonly DependencyProperty DisplayModeProperty = DependencyProperty.Register(nameof(DisplayMode), typeof(DisplayMode), typeof(TitleBar), new PropertyMetadata(DisplayMode.Standard, DisplayModeChanged));

/// <summary>
/// The backing <see cref="DependencyProperty"/> for the <see cref="CompactStateBreakpoint
/// "/> property.
/// </summary>
public static readonly DependencyProperty CompactStateBreakpointProperty = DependencyProperty.Register(nameof(CompactStateBreakpoint), typeof(int), typeof(TitleBar), new PropertyMetadata(850));

/// <summary>
/// The backing <see cref="DependencyProperty"/> for the <see cref="AutoConfigureCustomTitleBar"/> property.
/// </summary>
public static readonly DependencyProperty AutoConfigureCustomTitleBarProperty = DependencyProperty.Register(nameof(AutoConfigureCustomTitleBar), typeof(bool), typeof(TitleBar), new PropertyMetadata(true, AutoConfigureCustomTitleBarChanged));

#if WINAPPSDK
public static readonly DependencyProperty WindowProperty = DependencyProperty.Register(nameof(Window), typeof(Window), typeof(TitleBar), new PropertyMetadata(null));
/// <summary>
/// The backing <see cref="DependencyProperty"/> for the <see cref="Window"/> property.
/// </summary>
public static readonly DependencyProperty WindowProperty = DependencyProperty.Register(nameof(Window), typeof(Window), typeof(TitleBar), new PropertyMetadata(null));
#endif

public ImageSource Icon
/// <summary>
/// The event that gets fired when the back button is clicked
/// </summary>
public event EventHandler<RoutedEventArgs>? BackButtonClick;

/// <summary>
/// The event that gets fired when the pane toggle button is clicked
/// </summary>
public event EventHandler<RoutedEventArgs>? PaneButtonClick;

/// <summary>
/// Gets or sets the Icon
/// </summary>
public IconElement Icon
{
get => (ImageSource)GetValue(IconProperty);
get => (IconElement)GetValue(IconProperty);
set => SetValue(IconProperty, value);
}

/// <summary>
/// Gets or sets the Title
/// </summary>
public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}

/// <summary>
/// Gets or sets the Subtitle
/// </summary>
public string Subtitle
{
get => (string)GetValue(SubtitleProperty);
set => SetValue(SubtitleProperty, value);
}

/// <summary>
/// Gets or sets the content shown at the center of the TitleBar. When setting this, using DisplayMode=Tall is recommended.
/// </summary>
public object Content
{
get => (object)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}

/// <summary>
/// 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.
/// </summary>
public object Footer
{
get => (object)GetValue(FooterProperty);
set => SetValue(FooterProperty, value);
}

/// <summary>
/// Gets or sets DisplayMode. Compact is default (32px), Tall is recommended when setting the Content or Footer.
/// </summary>
public DisplayMode DisplayMode
{
get => (DisplayMode)GetValue(DisplayModeProperty);
set => SetValue(DisplayModeProperty, value);
}

/// <summary>
/// Gets or sets the visibility of the back button.
/// </summary>
public bool IsBackButtonVisible
{
get => (bool)GetValue(IsBackButtonVisibleProperty);
set => SetValue(IsBackButtonVisibleProperty, value);
}

/// <summary>
/// Gets or sets the visibility of the pane toggle button.
/// </summary>
public bool IsPaneButtonVisible
{
get => (bool)GetValue(IsPaneButtonVisibleProperty);
set => SetValue(IsPaneButtonVisibleProperty, value);
}

public bool ConfigureTitleBar
/// <summary>
/// Gets or sets the breakpoint of when the compact state is triggered.
/// </summary>
public int CompactStateBreakpoint
{
get => (int)GetValue(CompactStateBreakpointProperty);
set => SetValue(CompactStateBreakpointProperty, value);
}

/// <summary>
/// Gets or sets if the TitleBar should auto configure ExtendContentIntoTitleBar and CaptionButtion background colors.
/// </summary>
public bool AutoConfigureCustomTitleBar
{
get => (bool)GetValue(ConfigureTitleBarProperty);
set => SetValue(ConfigureTitleBarProperty, value);
get => (bool)GetValue(AutoConfigureCustomTitleBarProperty);
set => SetValue(AutoConfigureCustomTitleBarProperty, value);
}

#if WINAPPSDK
/// <summary>
/// Gets or sets the window the TitleBar should configure (WASDK only).
/// </summary>
public Window Window
{
get => (Window)GetValue(WindowProperty);
Expand All @@ -100,14 +185,26 @@ private static void IsPaneButtonVisibleChanged(DependencyObject d, DependencyPro
((TitleBar)d).Update();
}

private static void ConfigureTitleBarChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private static void DisplayModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((TitleBar)d).SetTitleBar();
((TitleBar)d).Update();
}

private static void DisplayModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private static void IconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((TitleBar)d).Update();
}

private static void AutoConfigureCustomTitleBarChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((TitleBar)d).SetTitleBar();
if (((TitleBar)d).AutoConfigureCustomTitleBar)
{
((TitleBar)d).Configure();
}
else
{
((TitleBar)d).Reset();
}
}
}

Expand Down
32 changes: 19 additions & 13 deletions CommunityToolkit.App.Shared/Controls/TitleBar/TitleBar.UWP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,41 @@

namespace CommunityToolkit.App.Shared.Controls;

[TemplatePart(Name = nameof(PART_DragRegion), Type = typeof(Grid))]

public partial class TitleBar : Control
{
Grid? PART_DragRegion;

private void SetUWPTitleBar()
{
if (ConfigureTitleBar)
if (AutoConfigureCustomTitleBar)
{
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
CoreApplication.GetCurrentView().TitleBar.LayoutMetricsChanged -= this.TitleBar_LayoutMetricsChanged;
CoreApplication.GetCurrentView().TitleBar.LayoutMetricsChanged += this.TitleBar_LayoutMetricsChanged;
Window.Current.Activated -= this.Current_Activated;
Window.Current.Activated += this.Current_Activated;
Window.Current.SetTitleBar(_dragRegion);

ApplicationView.GetForCurrentView().TitleBar.ButtonBackgroundColor = Colors.Transparent;
ApplicationView.GetForCurrentView().TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
Window.Current.SetTitleBar(PART_DragRegion);
PART_DragRegion = GetTemplateChild(nameof(PART_DragRegion)) as Grid;
}
else
{
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;
Window.Current.Activated -= this.Current_Activated;
CoreApplication.GetCurrentView().TitleBar.LayoutMetricsChanged -= this.TitleBar_LayoutMetricsChanged;
Window.Current.SetTitleBar(null);
ResetUWPTitleBar();
}
}

private void ResetUWPTitleBar()
{
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;
Window.Current.Activated -= this.Current_Activated;
CoreApplication.GetCurrentView().TitleBar.LayoutMetricsChanged -= this.TitleBar_LayoutMetricsChanged;
Window.Current.SetTitleBar(null);
}

private void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
{
if (e.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated)
Expand All @@ -47,13 +58,8 @@ private void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEve

private void TitleBar_LayoutMetricsChanged(CoreApplicationViewTitleBar sender, object args)
{
if (_titleBar != null)
{
ColumnDefinition Left = (ColumnDefinition)_titleBar.GetTemplateChild(PartLeftPaddingColumn);
ColumnDefinition Right = (ColumnDefinition)_titleBar.GetTemplateChild(PartRightPaddingColumn);
Left.Width = new GridLength(CoreApplication.GetCurrentView().TitleBar.SystemOverlayLeftInset);
Right.Width = new GridLength(CoreApplication.GetCurrentView().TitleBar.SystemOverlayRightInset);
}
PART_LeftPaddingColumn!.Width = new GridLength(CoreApplication.GetCurrentView().TitleBar.SystemOverlayLeftInset);
PART_RightPaddingColumn!.Width = new GridLength(CoreApplication.GetCurrentView().TitleBar.SystemOverlayRightInset);
}
}
#endif
Loading