mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +02:00
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
|
|
// Copyright (c) Microsoft Corporation
|
||
|
|
// 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;
|
||
|
|
|
||
|
|
using Microsoft.UI.Xaml;
|
||
|
|
using Microsoft.UI.Xaml.Controls;
|
||
|
|
|
||
|
|
namespace Microsoft.CmdPal.UI.Controls;
|
||
|
|
|
||
|
|
[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
|
||
|
|
[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")]
|
||
|
|
public partial class IsEnabledTextBlock : Control
|
||
|
|
{
|
||
|
|
public IsEnabledTextBlock()
|
||
|
|
{
|
||
|
|
this.Style = (Style)App.Current.Resources["DefaultIsEnabledTextBlockStyle"];
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void OnApplyTemplate()
|
||
|
|
{
|
||
|
|
IsEnabledChanged -= IsEnabledTextBlock_IsEnabledChanged;
|
||
|
|
SetEnabledState();
|
||
|
|
IsEnabledChanged += IsEnabledTextBlock_IsEnabledChanged;
|
||
|
|
base.OnApplyTemplate();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
|
||
|
|
"Text",
|
||
|
|
typeof(string),
|
||
|
|
typeof(IsEnabledTextBlock),
|
||
|
|
null);
|
||
|
|
|
||
|
|
[Localizable(true)]
|
||
|
|
public string Text
|
||
|
|
{
|
||
|
|
get => (string)GetValue(TextProperty);
|
||
|
|
set => SetValue(TextProperty, value);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void IsEnabledTextBlock_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||
|
|
{
|
||
|
|
SetEnabledState();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void SetEnabledState()
|
||
|
|
{
|
||
|
|
VisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled", true);
|
||
|
|
}
|
||
|
|
}
|