using System; using System.Windows; using System.Windows.Data; namespace Muchinfo.MTPClient.Infrastructure.Converters { //datagrid显示太长(显示部分数据后面跟省略号) public class StringSubstringConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = string.Empty; if (value != null) { string srt = (string)value; if (!string.IsNullOrEmpty(srt) && srt.Length > 20) { result = srt.Substring(0, 17) + "..."; } else { return value; } } return result; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } //datagrid根据文本长度是否显示tooltip public class StringVisableConver : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Visibility result = Visibility.Visible; string srt = (string)value; if (string.IsNullOrWhiteSpace(srt)) { result = Visibility.Collapsed; } else { if (srt.Length <= 20) { result = Visibility.Collapsed; } } return result; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } }