/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ContentIcon.cs
53 строки
2 KB
Jiří Polášek
CmdPal: Check icon parent before adding in ContentIcon (Closes: #40928) (#40931)
15 авг 2025, 14:48
Не верифицирован
15 авг 2025, 14:48
67cd0f0
Код
Авторство
О чём код?
// 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.Diagnostics; using CommunityToolkit.WinUI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; namespace Microsoft.CmdPal.UI.Controls; /// <summary> /// A helper control which takes an <see cref="IconSource"/> and creates the corresponding <see cref="IconElement"/>. /// </summary> public partial class ContentIcon : FontIcon { public UIElement Content { get => (UIElement)GetValue(ContentProperty); set => SetValue(ContentProperty, value); } public static readonly DependencyProperty ContentProperty = DependencyProperty.Register( nameof(Content), typeof(UIElement), typeof(ContentIcon), new PropertyMetadata(null)); public ContentIcon() { Loaded += IconBoxElement_Loaded; } private void IconBoxElement_Loaded(object sender, RoutedEventArgs e) { if (this.FindDescendants().OfType<Grid>().FirstOrDefault() is Grid grid && Content is not null) { if (grid.Children.Contains(Content)) { return; } if (Content is FrameworkElement element && element.Parent is not null) { Debug.Assert(false, $"IconBoxElement Content is already parented to {element.Parent.GetType().Name}"); return; } grid.Children.Add(Content); } } }