| 1 | // Copyright (C) Microsoft Corporation. All rights reserved. |
| 2 | |
| 3 | namespace WslSettings.Converters |
| 4 | { |
| 5 | public sealed class MegabyteNumberConverter : Microsoft.UI.Xaml.Data.IValueConverter |
| 6 | { |
| 7 | public object? Convert(object value, Type targetType, object parameter, string language) |
| 8 | { |
| 9 | if (value != null && UInt64.TryParse(value as string, out UInt64 parseResult)) |
| 10 | { |
| 11 | return (parseResult / Constants.MB).ToString(); |
| 12 | } |
| 13 | |
| 14 | return null; |
| 15 | } |
| 16 | |
| 17 | public object? ConvertBack(object value, Type targetType, object parameter, string language) |
| 18 | { |
| 19 | |
| 20 | if (value != null && UInt64.TryParse(value as string, out UInt64 parseResult)) |
| 21 | { |
| 22 | return (parseResult * Constants.MB).ToString(); |
| 23 | } |
| 24 | |
| 25 | return null; |
| 26 | } |
| 27 | } |
| 28 | } |