2026-02-12 16:45:44 +01:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2021-10-19 13:44:13 +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.ComponentModel;
|
2024-10-17 05:14:57 -04:00
|
|
|
|
2022-04-19 22:00:28 +02:00
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
using Microsoft.UI.Xaml.Controls;
|
2021-10-19 13:44:13 +02:00
|
|
|
|
2026-02-12 16:45:44 +01:00
|
|
|
namespace Microsoft.PowerToys.Common.UI.Controls
|
2021-10-19 13:44:13 +02:00
|
|
|
{
|
|
|
|
|
[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
|
|
|
|
|
[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")]
|
2024-09-11 08:36:34 -07:00
|
|
|
public partial class IsEnabledTextBlock : Control
|
2021-10-19 13:44:13 +02:00
|
|
|
{
|
|
|
|
|
public IsEnabledTextBlock()
|
|
|
|
|
{
|
2026-02-12 16:45:44 +01:00
|
|
|
this.DefaultStyleKey = typeof(IsEnabledTextBlock);
|
2021-10-19 13:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnApplyTemplate()
|
|
|
|
|
{
|
|
|
|
|
IsEnabledChanged -= IsEnabledTextBlock_IsEnabledChanged;
|
|
|
|
|
SetEnabledState();
|
|
|
|
|
IsEnabledChanged += IsEnabledTextBlock_IsEnabledChanged;
|
|
|
|
|
base.OnApplyTemplate();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-11 23:00:11 +01:00
|
|
|
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(IsEnabledTextBlock), new PropertyMetadata(null));
|
2021-10-19 13:44:13 +02:00
|
|
|
|
|
|
|
|
[Localizable(true)]
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
|
|
|
|
get => (string)GetValue(TextProperty);
|
|
|
|
|
set => SetValue(TextProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-11 23:00:11 +01:00
|
|
|
public static readonly DependencyProperty IsTextSelectionEnabledProperty = DependencyProperty.Register(nameof(IsTextSelectionEnabled), typeof(bool), typeof(IsEnabledTextBlock), new PropertyMetadata(false));
|
|
|
|
|
|
|
|
|
|
public bool IsTextSelectionEnabled
|
|
|
|
|
{
|
|
|
|
|
get => (bool)GetValue(IsTextSelectionEnabledProperty);
|
|
|
|
|
set => SetValue(IsTextSelectionEnabledProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 13:44:13 +02:00
|
|
|
private void IsEnabledTextBlock_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SetEnabledState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetEnabledState()
|
|
|
|
|
{
|
|
|
|
|
VisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled", true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|