VPet/VPet.Solution/Converters/StringFormatConverter.cs
2023-12-18 22:53:56 +08:00

52 lines
1.3 KiB
C#

using System.Windows.Data;
namespace VPet.House.Converters;
/// <summary>
/// 边距转换器
/// <para>示例:
/// <code><![CDATA[
/// <MultiBinding Converter="{StaticResource MarginConverter}">
/// <Binding Path="StringFormat" />
/// <Binding Path="Value1" />
/// <Binding Path="Value2" />
/// </MultiBinding>
/// OR
/// <MultiBinding Converter="{StaticResource MarginConverter}" ConverterParameter="{}{0}{1}">
/// <Binding Path="Value1" />
/// <Binding Path="Value2" />
/// </MultiBinding>
/// ]]></code></para>
/// </summary>
public class StringFormatConverter : IMultiValueConverter
{
public object Convert(
object[] values,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture
)
{
var formatStr = (string)parameter;
if (string.IsNullOrWhiteSpace(formatStr))
{
formatStr = (string)values[0];
return string.Format(formatStr, values.Skip(1).ToArray());
}
else
{
return string.Format(formatStr, values);
}
}
public object[] ConvertBack(
object value,
Type[] targetTypes,
object parameter,
System.Globalization.CultureInfo culture
)
{
throw new NotImplementedException();
}
}