-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathIFormattableToStringConverter.cs
More file actions
48 lines (42 loc) · 2.04 KB
/
IFormattableToStringConverter.cs
File metadata and controls
48 lines (42 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace CommunityToolkit.WinUI.Converters;
/// <summary>
/// Value converter that converts an <see cref="IFormattable"/> to a formatted <see cref="string"/>.
/// The string format needs to be passed as the converter parameter.
/// </summary>
public partial class IFormattableToStringConverter : IValueConverter
{
// TODO: Provide property to set a IFormatProvider for the 2nd parameter to ToString
/// <summary>
/// Convert an <see cref="IFormattable"/> value to a formatted <see cref="string"/>.
/// </summary>
/// <param name="value">The source data being passed to the target.</param>
/// <param name="targetType">The type of the target property, as a type reference.</param>
/// <param name="parameter">The format string.</param>
/// <param name="language">The language of the conversion. Not used.</param>
/// <returns>The formatted string.</returns>
public object Convert(object value, Type targetType, object parameter, string language)
{
var formattableValue = value as IFormattable;
var format = parameter as string;
if (formattableValue == null || format == null)
{
return value;
}
return formattableValue.ToString(format, null);
}
/// <summary>
/// Not implemented.
/// </summary>
/// <param name="value">The source data being passed to the target.</param>
/// <param name="targetType">The type of the target property, as a type reference.</param>
/// <param name="parameter">Optional parameter. Not used.</param>
/// <param name="language">The language of the conversion. Not used.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}