/ src / settings-ui / Settings.UI / Converters / ImageResizerUnitToIntConverter.cs
ImageResizerUnitToIntConverter.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  
 7  using Microsoft.PowerToys.Settings.UI.Library;
 8  using Microsoft.UI.Xaml.Data;
 9  
10  namespace Microsoft.PowerToys.Settings.UI.Converters;
11  
12  public sealed partial class ImageResizerUnitToIntConverter : IValueConverter
13  {
14      public object Convert(object value, Type targetType, object parameter, string language)
15      {
16          if (value is ResizeUnit)
17          {
18              return (int)value;
19          }
20  
21          return 0;
22      }
23  
24      public object ConvertBack(object value, Type targetType, object parameter, string language)
25      {
26          if (value is int intValue)
27          {
28              return (ResizeUnit)intValue;
29          }
30  
31          return ResizeUnit.Centimeter;
32      }
33  }