mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-06 01:30:52 +08:00
66 lines
2.0 KiB
C#
66 lines
2.0 KiB
C#
|
|
using System;
|
|||
|
|
using System.Globalization;
|
|||
|
|
using Windows.UI.Xaml.Data;
|
|||
|
|
|
|||
|
|
namespace LiveCharts.Uwp.Converters
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
/// <seealso cref="Windows.UI.Xaml.Data.IValueConverter" />
|
|||
|
|
public class StringFormatConverter : IValueConverter
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Converts the specified value.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="value">The value.</param>
|
|||
|
|
/// <param name="targetType">Type of the target.</param>
|
|||
|
|
/// <param name="parameter">The parameter.</param>
|
|||
|
|
/// <param name="language">The language.</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public object Convert(object value, Type targetType, object parameter, string language)
|
|||
|
|
{
|
|||
|
|
var format = (parameter as string) ?? Format;
|
|||
|
|
if (format == null)
|
|||
|
|
return value;
|
|||
|
|
|
|||
|
|
if (string.IsNullOrWhiteSpace(language))
|
|||
|
|
{
|
|||
|
|
return string.Format(format, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var culture = new CultureInfo(language);
|
|||
|
|
return string.Format(culture, format, value);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
return string.Format(format, value);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Converts the back.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="value">The value.</param>
|
|||
|
|
/// <param name="targetType">Type of the target.</param>
|
|||
|
|
/// <param name="parameter">The parameter.</param>
|
|||
|
|
/// <param name="language">The language.</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
/// <exception cref="System.NotImplementedException"></exception>
|
|||
|
|
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|||
|
|
{
|
|||
|
|
throw new NotImplementedException();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Gets or sets the format.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <value>
|
|||
|
|
/// The format.
|
|||
|
|
/// </value>
|
|||
|
|
public string Format { get; set; }
|
|||
|
|
}
|
|||
|
|
}
|