/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml.cs
56 строк
2 KB
Niels Laute
Creating a Common.UI.Controls lib (#45542)
12 фев 2026, 18:45
Не верифицирован
12 фев 2026, 18:45
75bf642
Код
Авторство
О чём код?
// 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.PowerToys.Common.UI.Controls { [TemplateVisualState(Name = "Normal", GroupName = "CommonStates")] [TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")] public partial class IsEnabledTextBlock : Control { public IsEnabledTextBlock() { this.DefaultStyleKey = typeof(IsEnabledTextBlock); } protected override void OnApplyTemplate() { IsEnabledChanged -= IsEnabledTextBlock_IsEnabledChanged; SetEnabledState(); IsEnabledChanged += IsEnabledTextBlock_IsEnabledChanged; base.OnApplyTemplate(); } public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(IsEnabledTextBlock), new PropertyMetadata(null)); [Localizable(true)] public string Text { get => (string)GetValue(TextProperty); set => SetValue(TextProperty, value); } 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); } private void IsEnabledTextBlock_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) { SetEnabledState(); } private void SetEnabledState() { VisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled", true); } } }