您给出的示例是针对非矩形容器的。如果不需要,可以使用值转换器。如果它比标签大,可以用椭圆表示:
未测试示例:
class EllipsisConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value,
Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string path = (string)value;
if (path.Length > 100)
{
return path.Substring(0, 100) + "...";
}else{
return path;
}
}
public object ConvertBack(object value,
Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}