I have a NumberBox control in my UWP project.
I want to use it to display a number of minutes, so I want the number on the box to be followed by "min" (e.g. "10 min").
I thought I could implement this using a NumberFormatter, but don't know how.
This is what I tried:
- Added
NumberFormatterclass
public class DurationFormatter : INumberFormatter2
{
public string FormatInt(long value)
{
return $"{value} min";
}
public string FormatDouble(double value)
{
return $"{value} min";
}
public string FormatUInt(ulong value)
{
return $"{value} min";
}
}
- Added reference to page resources
<Page.Resources>
<local1:DurationFormatter x:Key="Converter1"/>
</Page.Resources>
- Tried to add formatter to number box, but not sure how. This doesn't work:
<muxc:NumberBox x:Name="DurationNumberBox" SpinButtonPlacementMode="Compact"
Header="Duration" Value="{x:Bind DurationViewValue, Mode=TwoWay}"
ValidationMode="InvalidInputOverwritten"
NumberFormatter="{StaticResource Converter1}"/>
Any help appreciated.