BytesConverter
Posted redsky
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BytesConverter相关的知识,希望对你有一定的参考价值。
public class BytesConverter : IValueConverter { public bool IsSpeed { get; set; } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double kb = 1024.00 * 1024; double mb = 1024.00 * 1024 * 1024; double gb = 1024.00 * 1024 * 1024 * 1024; double bytes = value == null ? 0 : (long)(value); string result = null; if (bytes < kb) result = (bytes / 1024.00).ToString("N2") + "B"; else if (bytes >= kb && bytes < mb) result = (bytes / kb).ToString("N2") + "KB"; else if (bytes >= mb && bytes < gb) result = (bytes / mb).ToString("N2") + "MB"; else result = bytes / gb + "GB"; if (IsSpeed) result += "/s"; return result; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return System.Windows.Data.Binding.DoNothing; } }
以上是关于BytesConverter的主要内容,如果未能解决你的问题,请参考以下文章