2026-01-28 10:37:22 +08:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2021-09-06 20:21:18 +02:00
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2026-01-28 10:37:22 +08:00
|
|
|
using CommunityToolkit.WinUI.Controls;
|
2022-04-19 22:00:28 +02:00
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
using Microsoft.UI.Xaml.Controls;
|
2021-09-06 20:21:18 +02:00
|
|
|
|
2026-02-12 16:45:44 +01:00
|
|
|
namespace Microsoft.PowerToys.Common.UI.Controls
|
2021-09-06 20:21:18 +02:00
|
|
|
{
|
2026-01-28 10:37:22 +08:00
|
|
|
public sealed partial class ShortcutWithTextLabelControl : Control
|
2021-09-06 20:21:18 +02:00
|
|
|
{
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
|
|
|
|
get { return (string)GetValue(TextProperty); }
|
|
|
|
|
set { SetValue(TextProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-20 09:31:52 +08:00
|
|
|
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(ShortcutWithTextLabelControl), new PropertyMetadata(default(string)));
|
2021-09-06 20:21:18 +02:00
|
|
|
|
|
|
|
|
public List<object> Keys
|
|
|
|
|
{
|
|
|
|
|
get { return (List<object>)GetValue(KeysProperty); }
|
|
|
|
|
set { SetValue(KeysProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-20 09:31:52 +08:00
|
|
|
public static readonly DependencyProperty KeysProperty = DependencyProperty.Register(nameof(Keys), typeof(List<object>), typeof(ShortcutWithTextLabelControl), new PropertyMetadata(default(string)));
|
|
|
|
|
|
2026-01-28 10:37:22 +08:00
|
|
|
public Placement LabelPlacement
|
2025-08-20 09:31:52 +08:00
|
|
|
{
|
2026-01-28 10:37:22 +08:00
|
|
|
get { return (Placement)GetValue(LabelPlacementProperty); }
|
2025-08-20 09:31:52 +08:00
|
|
|
set { SetValue(LabelPlacementProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 10:37:22 +08:00
|
|
|
public static readonly DependencyProperty LabelPlacementProperty = DependencyProperty.Register(nameof(LabelPlacement), typeof(Placement), typeof(ShortcutWithTextLabelControl), new PropertyMetadata(defaultValue: Placement.After, OnIsLabelPlacementChanged));
|
|
|
|
|
|
|
|
|
|
public MarkdownConfig MarkdownConfig
|
|
|
|
|
{
|
|
|
|
|
get { return (MarkdownConfig)GetValue(MarkdownConfigProperty); }
|
|
|
|
|
set { SetValue(MarkdownConfigProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty MarkdownConfigProperty = DependencyProperty.Register(nameof(MarkdownConfig), typeof(MarkdownConfig), typeof(ShortcutWithTextLabelControl), new PropertyMetadata(new MarkdownConfig()));
|
|
|
|
|
|
|
|
|
|
public Style KeyVisualStyle
|
|
|
|
|
{
|
|
|
|
|
get { return (Style)GetValue(KeyVisualStyleProperty); }
|
|
|
|
|
set { SetValue(KeyVisualStyleProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty KeyVisualStyleProperty = DependencyProperty.Register(nameof(KeyVisualStyle), typeof(Style), typeof(ShortcutWithTextLabelControl), new PropertyMetadata(default(Style)));
|
2021-09-06 20:21:18 +02:00
|
|
|
|
|
|
|
|
public ShortcutWithTextLabelControl()
|
|
|
|
|
{
|
2026-01-28 10:37:22 +08:00
|
|
|
DefaultStyleKey = typeof(ShortcutWithTextLabelControl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnApplyTemplate()
|
|
|
|
|
{
|
|
|
|
|
base.OnApplyTemplate();
|
2021-09-06 20:21:18 +02:00
|
|
|
}
|
2025-08-20 09:31:52 +08:00
|
|
|
|
|
|
|
|
private static void OnIsLabelPlacementChanged(DependencyObject d, DependencyPropertyChangedEventArgs newValue)
|
|
|
|
|
{
|
|
|
|
|
if (d is ShortcutWithTextLabelControl labelControl)
|
|
|
|
|
{
|
2026-01-28 10:37:22 +08:00
|
|
|
if (labelControl.LabelPlacement == Placement.Before)
|
2025-08-20 09:31:52 +08:00
|
|
|
{
|
2026-01-28 10:37:22 +08:00
|
|
|
VisualStateManager.GoToState(labelControl, "LabelBefore", true);
|
2025-08-20 09:31:52 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VisualStateManager.GoToState(labelControl, "LabelAfter", true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 10:37:22 +08:00
|
|
|
public enum Placement
|
|
|
|
|
{
|
|
|
|
|
Before,
|
|
|
|
|
After,
|
|
|
|
|
}
|
2021-09-06 20:21:18 +02:00
|
|
|
}
|
|
|
|
|
}
|