<DataGridTextColumn
    MinWidth="150"
    Binding="{Binding Converter={StaticResource WeightToStringConveter}}"
    ElementStyle="{StaticResource CenterTextBlockStyle}"
    Header="重量" />
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
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();
        }
    }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.