1 // -------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 // -------------------------------------------------------------------
4 //From \\authoring\Sparkle\Source\1.0.1083.0\Common\Source\Framework\Properties
5 namespace System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.PropertyInspector
9 using System.Activities.Presentation.PropertyEditing;
10 using System.ComponentModel;
11 using System.Windows.Media;
12 using System.Globalization;
14 internal class NewItemFactoryTypeModel
17 private NewItemFactory factory;
18 private Size desiredSize;
19 private IMessageLogger exceptionLogger;
21 public NewItemFactoryTypeModel(Type type, NewItemFactory factory)
24 this.factory = factory;
25 this.desiredSize = new Size(0, 0);
26 this.exceptionLogger = null;
29 public NewItemFactoryTypeModel(Type type, NewItemFactory factory, IMessageLogger exceptionLogger) : this(type, factory)
31 this.exceptionLogger = exceptionLogger;
34 public string DisplayName
36 get { return this.factory.GetDisplayName(this.type); }
41 get { return this.type; }
48 object image = this.factory.GetImage(this.type, this.desiredSize);
49 ImageSource imageSource = image as ImageSource;
50 if (imageSource != null && imageSource is ISupportInitialize)
54 double dummyHeight = imageSource.Height;
56 catch (InvalidOperationException exception)
58 this.ReportException(string.Format(CultureInfo.CurrentCulture, ExceptionStringTable.NewItemFactoryIconLoadFailed, this.factory.GetType().Name, exception.Message));
65 public Size DesiredSize
67 get { return this.desiredSize; }
68 set { this.desiredSize = value; }
71 public NewItemFactory ItemFactory
73 get { return this.factory; }
76 public object CreateInstance()
78 return this.factory.CreateInstance(this.type);
81 private void ReportException(string message)
83 if (this.exceptionLogger != null)
85 this.exceptionLogger.WriteLine(message);
90 // Seems like the ComboBoxAutomation peer, calls the object.ToString() to read out
91 // the item, if the item doesnt have its content set when queried by AutomationClient.
92 // As a result, when this NewItemFactoryTypeModel,
93 // is added to the combo-box in a SubPropertyEditor, we need to return the DisplayName
94 // property in the ToString() implementation so that that the AutomationClient
95 // reads out the correct value instead of the type of the object.
97 // <returns></returns>
98 public override string ToString()