Files
PowerToys/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ContentIcon.cs
Mike Griese 325b1a1441 CmdPal: Remove vestigial try/catch (#40815)
This was added in #38040 but appears to be vestigial now.

RE: #40113
2025-07-28 18:47:18 -05:00

42 lines
1.2 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 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)
{
grid.Children.Add(Content);
}
}
}