mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
52 lines
1.3 KiB
C#
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();
|
|
}
|
|
}
|