<DataGridTextColumn
MinWidth="150"
Binding="{Binding Converter={StaticResource WeightToStringConveter}}"
ElementStyle="{StaticResource CenterTextBlockStyle}"
Header="重量" />
namespace Pipette.Converter
{
public class WeightToStringConveter : IValueConverter
{
private readonly string[] Units = new[]
{
"g", "mg", "ct", "oz", "lb"
};
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var tbDeviceData = value as TbDeviceData;
if (tbDeviceData == null) return "";
return tbDeviceData.Weight + Units[tbDeviceData.WeightUnit];
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}