/ src / settings-ui / Settings.UI.Controls / Converters / ModuleListSortOptionToBooleanConverter.cs
ModuleListSortOptionToBooleanConverter.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.UI.Xaml.Data;
 7  
 8  namespace Microsoft.PowerToys.Settings.UI.Controls.Converters
 9  {
10      public partial class ModuleListSortOptionToBooleanConverter : IValueConverter
11      {
12          public object Convert(object value, Type targetType, object parameter, string language)
13          {
14              if (value is ModuleListSortOption sortOption && parameter is string paramString)
15              {
16                  if (Enum.TryParse(typeof(ModuleListSortOption), paramString, out object? result) && result != null)
17                  {
18                      return sortOption == (ModuleListSortOption)result;
19                  }
20              }
21  
22              return false;
23          }
24  
25          public object ConvertBack(object value, Type targetType, object parameter, string language)
26          {
27              if (value is bool isChecked && isChecked && parameter is string paramString)
28              {
29                  if (Enum.TryParse(typeof(ModuleListSortOption), paramString, out object? result) && result != null)
30                  {
31                      return (ModuleListSortOption)result;
32                  }
33              }
34  
35              return ModuleListSortOption.Alphabetical;
36          }
37      }
38  }