1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //------------------------------------------------------------
5 namespace System.Activities.Presentation.View
7 using System.Windows.Data;
8 using System.Activities.Presentation.Model;
10 internal class BreadCrumbTextConverter : IMultiValueConverter
12 const int MaxDisplayNameLength = 20;
13 double pixelsPerChar = 6.5;
15 internal double PixelsPerChar
17 get { return this.pixelsPerChar; }
18 set { this.pixelsPerChar = Math.Max(5.0, value); }
21 public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
23 int actualDisplayNameLength = MaxDisplayNameLength;
24 ModelItem boundModelItem = values[0] as ModelItem;
26 // default to root item's typename
27 string breadCrumbText = (null != boundModelItem ? boundModelItem.ItemType.Name : "<null>");
28 // if there is a display name property on root use that as the file name.
29 if (values[1] is ModelItem)
31 ModelItem displayNameProperty = (ModelItem)values[1];
32 if (typeof(string) == displayNameProperty.ItemType)
34 values[1] = displayNameProperty.GetCurrentValue();
37 if (values[1] is string)
39 string displayName = (string)values[1];
40 if (!displayName.Equals(string.Empty))
42 breadCrumbText = displayName;
45 if (values.Length == 3 && values[2] is double)
47 double actualControlWidth = (double)values[2];
48 actualDisplayNameLength = (int)Math.Max(MaxDisplayNameLength, actualControlWidth / pixelsPerChar);
51 if (breadCrumbText.Length > actualDisplayNameLength)
53 breadCrumbText = breadCrumbText.Substring(0, actualDisplayNameLength - 3) + "...";
55 return breadCrumbText;
58 public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
60 throw FxTrace.Exception.AsError(new InvalidOperationException());