/ src / settings-ui / Settings.UI / Converters / ServiceTypeToIconConverter.cs
ServiceTypeToIconConverter.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System;
 6  using Microsoft.PowerToys.Settings.UI.Library;
 7  using Microsoft.UI.Xaml.Controls;
 8  using Microsoft.UI.Xaml.Data;
 9  using Microsoft.UI.Xaml.Media.Imaging;
10  
11  namespace Microsoft.PowerToys.Settings.UI.Converters;
12  
13  public partial class ServiceTypeToIconConverter : IValueConverter
14  {
15      public object Convert(object value, Type targetType, object parameter, string language)
16      {
17          if (value is not string serviceType || string.IsNullOrWhiteSpace(serviceType))
18          {
19              return new ImageIcon { Source = new SvgImageSource(new Uri(AIServiceTypeRegistry.GetIconPath(AIServiceType.OpenAI))) };
20          }
21  
22          var iconPath = AIServiceTypeRegistry.GetIconPath(serviceType);
23          return new ImageIcon { Source = new SvgImageSource(new Uri(iconPath)) };
24      }
25  
26      public object ConvertBack(object value, Type targetType, object parameter, string language)
27      {
28          throw new NotImplementedException();
29      }
30  }