Humanizer
Humanizer copied to clipboard
Humanizer.Wpf
I feel like there should be a number of Humanizer WPF converters that can be used on bindings and such. I can't seem to find such a package.
Does one exist? If not, would a PR creating it be accepted?
Do you have examples of what you might find useful? I think the main reason we haven't been done yet is that they're generally easy and often have to handle application-specific nuances with display/input.
Hi @clairernovotny - It would be super helpful if there were WPF converters that could be used in XAML bindings.
None of the converters would be particularly complex, but it would be really nice to have them pre-built so I can just leverage them.
For example, I might have XAML like the following:
<TextBlock>
<Run Text="There are" />
<Run Text="{Binding DataModel.Count, Converter={StaticResource QuantityConverter}, ConverterParameter=Apples}" />
<Run Text="in the barrel." />
</TextBlock>
And use code like the following:
public class QuantityConverter : NumberConverter {
public string Unit { get; set; } = "Unit";
public ShowQuantityAs ShowQuantityAs { get; set; } = ShowQuantityAs.Numeric;
private static string GetUnit(params object?[] parameters) {
var tret = parameters.Where(x => x is { }).FirstOrDefault();
var ret = $@"{tret}";
return ret;
}
protected override string? Convert(int Input, object parameter, CultureInfo culture) {
var ret = GetUnit(parameter, Unit).ToQuantity(Input, ShowQuantityAs);
return ret;
}
protected override string? Convert(long Input, object parameter, CultureInfo culture) {
var ret = GetUnit(parameter, Unit).ToQuantity(Input, ShowQuantityAs);
return ret;
}
protected override string? Convert(double Input, object parameter, CultureInfo culture) {
var ret = GetUnit(parameter, Unit).ToQuantity(Input);
return ret;
}
}