// 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.Runtime.InteropServices;
using CommunityToolkit.WinUI;
using ManagedCommon;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace Microsoft.CmdPal.UI.Controls;
///
/// A helper control which takes an and creates the corresponding .
///
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().FirstOrDefault() is Grid grid && Content is not null)
{
try
{
grid.Children.Add(Content);
}
catch (COMException ex)
{
Logger.LogError(ex.ToString());
}
}
}
}