CSharpUtilities Contains static generic ToArray method for producing an Array from a collection. Static generic method produces a new array of the generic parameter type from the given ICollection. Target array item type Source collection. All items in this collection will be placed in the returned array. A new array of Ts containing the items from collection. Generates a new array from a subset of the source array. This version copies from the given index until the end of the array. Example: int[] source = {0,1,2,3,4,5}; int[] result = ArrayProducer.Slice(source, 3); // result is now: {3,4,5} result = ArrayProducer.Slice(source, 6); // result is now: {} Slice can operate on multidimensional arrays, but it only considers the first array. The array item type. Source array, the selected elements from here will be copied into the new array. The index at which to start selecting elements. A new array of size source.Length - fromIndex, containing the elements from source[fromIndex] until source[source.Length - 1]. Generates a new array from a subset of the source array. This version copies the given length of elements starting from the given index. Example: int[] source = {0,1,2,3,4,5}; int[] result = ArrayProducer.Slice(source, 3, 2); // result is now: {3,4} result = ArrayProducer.Slice(source, 5, 2); // result is now: {5, 0} 0 is the default value for int result = ArrayProducer.Slice(source, 0, 0); // result is now: {} Slice can operate on multidimensional arrays, but it only considers the first array. The array item type. Source array, the selected elements from here will be copied into the new array. The index at which to start selecting elements. The desired length of the resulting array. Up to this many elements will be copied from the source array. Fewer than length will be copied if length exceeds the size of the array past fromIndex. Any value less than 0 will be clamped to 0. A new array of size length, containing the elements from source[fromIndex] until source[Math.Min(source.Length - 1, fromIndex + length - 1)] and padded with null or default values at the end as necessary. Converts a set of Boolean input values into a single Boolean output value by performing a logical 'and.' May be used in XAML as a markup extension. Common instance of this converter. May be shared to reduce memory demands, and provided by the MarkupExtension. Convert from multiple Boolean input values to a single Boolean output using a logical 'and.' Input values, expected to be bool. Type of the output value. Must be assignable from bool. Ignored. Ignored. The result of combining the input values using a logical 'and' operation. Not supported. Throws a NotImplementedException. Ingored. Ignored. Ignored. Ignored. Never returns. Implements the MarkupExtension interface to return the shared Converter. Not used. The Converter instance. This is not a real converter, but rather a useful stand-in to help you debug a binding. Constructor. Put breakpoint here. standard standard standard standard standard not used. standard standard standard standard standard Provides the single static instance of this converter. Convert a boolean value to an Orientation value and vice versa true is converted horizontal false is converted vertical Convert a boolean value to an Orientation value Convert an Orientation value to a boolean value Adapts any converter that outputs a boolean into a Visibility value. Deals generically with the case where you need to bind the result of one converter's calculation to a Visibility value. Constructor Forwards this call to SubConverter.Convert(object,Type,object,CultureInfo) and turns the expected boolean value to a Visibility value. If the result is false, then IsNotVisibleTarget is returned. see IValueConverter interface see IValueConverter interface see IValueConverter interface see IValueConverter interface if SubConverter returns true, then Visible is returned, otherwise IsNotVisibleTarget is returned. Not implemented. see IValueConverter interface see IValueConverter interface see IValueConverter interface see IValueConverter interface throws an exception if called A Converter that outputs a boolean. The Visibility returned if the converter returns false. This property can be used to return Visibility.Hidden instead of Visibility.Collapsed. Same as the WPF standed BooleanToVisibilityConverter, except that you can specify the visibility target when the bound value returns false. Constructor When the property is bound to a boolean value, the value that is targeted when the value is false. By default, returns Visibility.Collapsed. Converts from boolean value to Visibility value. True will return Visibility.Visible, false will return the value of TargetHiddenVisibility. bound value not used not used not used Not implemented. Not implemented. Not implemented. Not implemented. Not implemented. An inverter version of a classic BooleanToVisibility converter. Convert function. see docs see docs see docs see docs If false, return Visible, else Collapsed. Unconvert function. see docs see docs see docs see docs If Visible, return false, else true. Converts a Boolean value by inverting it. May be used in XAML as a markup extension. Common instance of this converter. May be shared to reduce memory demands, and provided by the MarkupExtension. Invert the given value. Value to invert Target type of the conversion. Must be bool. Ignored. Ignored. true if value is false, false if value is true, and DependencyProperty.UnsetValue if value is DependencyProperty.UnsetValue. Invert the given value. Value to invert Target type of the conversion. Must be bool. Ignored. Ignored. true if value is false, false if value is true, and DependencyProperty.UnsetValue if value is DependencyProperty.UnsetValue. Implements the MarkupExtension interface to return the shared Converter. Not used. The Converter instance. Test fixture for general-purpose converters. Converts from Enum values to human-readable localizable Strings. The human-readable strings can be set directly, or can be inferred from a ReferenceDictionary. The Enum type to perform conversions on. A Dictionary that contains the comma-seperated string definition of the enum human-readable values to use. These strings should also be localized. This value can either be set directly, or it can be inferred by setting the ReferenceDictionary on the converter. The converter will attempt to look for value with a key equal to the Full class name of the Enum type being converted. If the AvailableValues array cannot be constructed, then the converter will throw an exception. Converts from an Enum value to a corresponding human-readable string version of the enum drawn from AvailableValues. The enum value. The target type is String. not used not used The converted value. Converts from a human-readable string drawn from AvailableValues to a corresponding Enum value. The human-readable string value. The target Enum type. not used not used The converted value. Contains the array of human-readable values. This value can either be set directly, or it can be inferred by setting the ReferenceDictionary on the converter. The converter will attempt to look for value with a key equal to the Full class name of the Enum type being converted. If the AvailableValues array cannot be constructed, then the converter will throw an exception. Returns true if the value is greater than zero. Only works with types that are assignable to Int32. Common instance of this converter. May be shared to reduce memory demands, and provided by the MarkupExtension. Returns true if the integer value passed in is greater than zero. see IValueConverter interface see IValueConverter interface see IValueConverter interface see IValueConverter interface true if > 0. Returns DependencyProperty.UnsetValue if an invalid value type is bound. Not implemented. see IValueConverter interface see IValueConverter interface see IValueConverter interface see IValueConverter interface throws an exception if called Implements the MarkupExtension interface to return the shared Converter. Not used. The Converter instance. Converts a sequence of booleans and returns Visible or Collapsed according to the logical result. You can make this and AND gate, or an OR gate, by setting the LogicalAnd boolean property. If you make it an AND gate, then we respect parameter ordering so that an effective null check can be introduced earlier that will result in a later, possibly invalid argument being skipped. This is similar to:
if(null != ref AND ref.SomeProperty) {
Similarly, a true result on an OR will always result in an early exit.
Default constructor Converts from a sequence of boolean values to a visibility value. See Class description remarks for comments regarding parameter precedence. series of booleans to evaluate standard not used not used Visibility.Visible if true, Visibility.Collapsed if false Not used. standard standard standard standard not used If true, this converter will perform a logical and on the parameters. Otherwise Performs an AND on a list of booleans and returns the NOT value of this. May be used in XAML as a markup extension. Common instance of this converter. May be shared to reduce memory demands, and provided by the MarkupExtension. Convert from multiple Boolean input values to a single Boolean output using a logical 'and'. Returns the NOT of this evaluation. Input values, expected to be bool. Type of the output value. Must be assignable from bool. Ignored. Ignored. The result of combining the input values using a logical 'and' operation, NOT-ed. Not supported. Throws a NotImplementedException. Ingored. Ignored. Ignored. Ignored. Never returns. Implements the MarkupExtension interface to return the shared Converter. Not used. The Converter instance. Allows control to bind to a property and only be Visible if the property is not null. When null, converter returns the value of VisibilityWhenNull, which is Visibility.Collapsed by default. Constructor The Visibility returned by this converter when bound source is null. Converts a bound source to Visibility, based on whether it's null or not. the binding source not used not used not used Visibility.Visible if not null, or VisibilityWhenNull Not implemented. Not implemented. Not implemented. Not implemented. Not implemented. Not implemented. An instance of the converter. Not static because the converter has a member variable. not used An instance of the converter. Converts a set of Boolean input values into a single Boolean output value by performing a logical 'or.' May be used in XAML as a markup extension. Common instance of this converter. May be shared to reduce memory demands, and provided by the MarkupExtension. Convert from multiple Boolean input values to a single Boolean output using a logical 'or.' Input values, expected to be bool. Type of the output value. Must be assignable from bool. Ignored. Ignored. The result of combining the input values using a logical 'or' operation. Not supported. Throws a NotImplementedException. Ingored. Ignored. Ignored. Ignored. Never returns. Implements the MarkupExtension interface to return the shared Converter. Not used. The Converter instance. SelectMaxDoubleConverter converts an array of doubles to the max value from the array Choose the max value from the array of doubles List of doubles The type of the binding target property The converter parameter to use The culture to use in the converter the max double value from the list Convert back is not implemented It throws a NotImplementedException exception when is used Implements the MarkupExtension interface to return the shared Converter. Not used. The Converter instance. Returns true if the passes in string is not null or empty. Returns true if the passes in string is not null or empty. standard standard standard standard Converts passed in value to a string, returns true if the passes in string is not null or empty. Not implemented. Not implemented. Not implemented. Not implemented. Not implemented. Not implemented. Provides the instance used by the markup extension syntax. not used Provides the instance used by the markup extension syntax. Returns true if the passes in string is null or empty. Returns true if the passes in string is null or empty. standard standard standard standard Converts passed in value to a string, returns true if the passes in string is null or empty. Not implemented. Not implemented. Not implemented. Not implemented. Not implemented. Not implemented. Provides the instance used by the markup extension syntax. not used Provides the instance used by the markup extension syntax. Removes ampersand hotkey markers from menu text. Takes menu text with potential ampersand hotkey markers and strips them. value to convert not used not used not used Text without ampersands. Not implemented. not used not used not used not used not used Returns a static instance of the converter. not used a static instance of the converter CSharpCompilationHelper is a helper class for compiling a c# string as an assembly, and loading that assembly. All hail: https://kenslearningcurve.com/tutorials/compiling-c-code-at-runtime https://kenslearningcurve.com/tutorials/run-compiled-c-code-at-runtime Compile a c# string as an assembly and load that assembly. All assemblies currently loaded by max are automatically referenced. Source string. An array of additional assemblies to reference. The loaded assembly. Convenient stand-in for the thread-safe delegate invocation idiom. For example, instead of invoking a Click event handler in a thread-safe manner by writing: EventHandler<EventArgs> threadSafeDelegateCopy = Click; if(null != threadSafeDelegateCopy) { threadSafeDelegateCopy(this, EventArgs.Empty); } It can be invoked equivalently, but more simply using the DelegateCaller as: DelegateCaller.Call(Click, this, EventArgs.Empty); Construct a DelegateCaller to call the given Delegate d. The delegate to safely call. Is the encapsulated delegate valid and callable? Calls the encapsulated delegate (possibly a multicast delegate) and returns the object returned by the delegate. Traps any thrown exception. Arguments passed to the delegate The delegate's return value. Call the given delegate or event with the given arguments. The delegate to call. The C# params modifier is roughly equivalent to the C++ ellipsis (...). It will build the args parameter array from the caller site parameter list. In this case, the arguments must be of the type and in the order expected by the delegate. The delgate's return value. The encapsulated delegate. This is an adpater of System.Windows.Forms.Screen, in order to get rid of System.Windows.Forms dependency for WPF dlls. I choose the name "DesktopScreen" just don't want to mess up with some existing code that uses System.Windows.Forms.Screen(e.g. UserInterfaceUtilities). Return an Screen object that contains a specified point. The testing point. Adapts System.Windows.Forms.Screen.Bounds. Adapts System.Windows.Forms.Screen.DeviceName. Constructor The underlying System::Windows::Forms::Screen object. the underlying System::Windows::Forms::Screen object Adding this attribute to a class that is instantiated via the Max bootstrapping mechanism will provide 'natural' keyboard focus selection for elements that desire it. This is mainly used to mark-up the MaxTextBox as being keyboard focus sensitive (so that Max does not intercept keyboard commands and run that as command hotkeys). Any other FrameworkElement that needs keyboard focus can add this attribute to the class declaration to have Max assign it automatically. Static class that contains function useful for UI DPI scaling. Return the dpi scale factor. monitor ID. The dpi scale factor. Return the dpi scale factor. The dpi scale factor. Return the user scale factor. The user scale factor. Scales the given measure according to DPI. measurement to scale. DPI scaled measure. Scales the given size according to DPI. size to scale. DPI scaled size. Scales the given size according to DPI. width to scale. height to scale. DPI scaled System.Drawing.Size. Dummy Enumerable to serve as a wrapper around an Enumerator for easy use in a foreach loop. Given an enumerator for performing a custom iteration, this class serves to spare the work of also creating an Enumerable just so that the enumerator can be used in a foreach loop. This class is generally used as: foreach(object myobject in new Enumerable<object>(myCustomEnumerator))... Type over which the Enumerator enumerates. Constructor taking the target enumerator. The enumerator to use for enumeration. Get the encapsulated enumerator. The encapsulated enumerator. Get the encapsulated enumerator. The encapsulated enumerator. The encapsulated enumerator. Provides an extension of the typesafe enum idiom for complex types. The enumerated type. The standard .NET enum implementation allows the programmer to create a set of named object instances around one of the primitive data types such as int or byte. ExtendedEnum provides much of enum's functionality around any user-defined, preferably immutable, type that inherits from it. This version of ExtendedEnum uses the curiously recursive template pattern to allow users to create an Enum whose underlying value is the class itself. To use ExtendedEnum, create a derived class in which the set of instances are defined as static constant members of the class. For example, say we want a predefined set of Balls each defined by its radius and bounciness, we could declare these as an ExtendedEnum: class Ball : ExtendedEnum<Ball> { public static readonly Ball Golf = new Ball(1, 10); public static readonly Ball Billiard = new Ball(2, 1); public static readonly Ball Baseball = new Ball(3, 3); public static readonly Ball Soccer = new Ball(8, 4); public static readonly Ball Basketball = new Ball(10, 5); // etc public int Radius { get { return mRadius;} } public int Bounciness { get { return mBounciness;} } private Ball(int radius, int bounciness) { mRadius = radius; mBounciness = bounciness; } private int mRadius; private int mBounciness; } Client code may now refer to members of the Ball enumeration as Ball.Golf or Ball.Billiard, much as it would for any standard enumeration. This enumeration is also closed at compile time since the constructor is private. When creating a class such as Ball which inherits from ExtendedEnum, the generic parameter T must be the generic class itself (i.e. Ball) or one of its base classes. class Ball : ExtendedEnum<Ball> // Valid {...} class TennisRacket : ExtendedEnum <Ball> // Invalid {...} Note: This will add values to ExtendedEnum<Ball> class SpecializedBall : Ball // Valid. {...} The underlying type exposed as an Enum through this class. Produces an array of all the Enum's members. Changing the returned array will not affect this ExtendedEnum type. Finds the ExtendedEnum member wrapping the given value. The value to find in this Enum. Either the found Enum member or null if no member is found. Determine if this ExtendedEnum type contains the given value. The value to try to find. true if value is found as a member of this Enum, false if not. Determine if this ExtendedEnum type contains the given value. The value to try to find. true if value is found as a member of this Enum, false if not. Determine the equality of this ExtendedEnum member to another ExtendedEnum member. The equivalence is established based on the rank of the extended enum elements. The other ExtendedEnum for comparison. true if this.Id == other.Id, false if not. Determine the equality of this ExtendedEnum member to another value. The equivalence is established based on the rank of the extended enum elements. T value against which to compare this ExtendedEnum member. true if this.Id == other.Id. Determine the equality of this ExtendedEnum member to another object. object against which to compare this ExtendedEnum member. Returns false if other is null. Returns true if other is referentially equal to this. Returns true if other is a T and this.Equals( (T)other ). Returns true if other is an ExtendedEnum<T> and this.Equals( (ExtendedEnum<T>)other ). Returns false otherwise. Get a hash code for this ExtendedEnum member. A hash code dependent on this enum type and on this enum member's Id. Compare this to another member of this ExtendedEnum, ordered according to their Ids. Other member against which to compare. <0 if this member is ranked first, 0 if they are the same member, and >0 if other should be ranked first. The underlying T value wrapped in this ExtendedEnum. Static constructor For the Ball example above, the static fields Ball.GolfBall, Ball.Basketball are initialized in the static constructor. According to the .Net specifications, a static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced. If clients would call: Ball.Values, before any field in Ball would be referenced (e.g. Ball.BasketBall.DoSomething()), then the Values array would be empty. This happens because the .Net compiler performs optimizations and does not call the derived class' (e.g. Ball) static constructor. Instead, it calls base.Values. To avoid this, we use reflection to reference a static field in the caller class which will trigger the call to the derived class' static constructor. Constructor intended for the default case, where the enumerated type is the derived type. Also checks to see if the curiously recursive template pattern requirements are satisfied. Provides the next Id value to assign to an Enum member added to the list. The next id is maintained in this counter instead of using sValues.Count to be future-proof against the possibility of removing Enum members from the list. The list of members in this Enum. Provides an extension of the typesafe enum idiom for complex types. The enumerated type. The underlying value type. The standard .NET enum implementation allows the programmer to create a set of named object instances around one of the primitive data types such as int or byte. ExtendedEnum provides much of enum's functionality around any user-defined, preferably immutable, type. This version of ExtendedEnum allows users to create an Enum whose underlying value is a user-defined or primitive type. It also uses the curiously recursive template pattern to ensure that enums with the same Underlying type, which are derived from different classes, do not share their values. To use ExtendedEnum, create a derived class in which the set of instances are defined as static constant members of the class. For example, say we want a predefined set of Balls with their name (String) as their UnderlyingValue, each defined by their name, radius and bounciness, we could declare these as an ExtendedEnum: class Ball : ExtendedEnum<Ball, String> { public static readonly Ball Golf = new Ball("Golf", 1, 2); public static readonly Ball Billiard = new Ball("Billiard", 3, 2); public static readonly Ball Baseball = new Ball("Baseball", 4, 3); public static readonly Ball Soccer = new Ball("Soccer", 10, 7); public static readonly Ball Basketball = new Ball("Basketball", 12, 10); // etc public String Name {get { return mName;} } public int Radius { get { return mRadius;} } public int Bounciness { get { return mBounciness;} } private Ball(String name, int radius, int bounciness) : base(name) { mName = name; mRadius = radius; mBounciness = bounciness; } private String name; private int mRadius; private int mBounciness; } Client code may now refer to members of the Ball enumeration as Ball.Golf or Ball.Billiard, much as it would for any standard enumeration. This enumeration is also closed at compile time since the constructor is private. When creating a class such as Ball which inherits from ExtendedEnum, the generic parameter T must be the generic class itself (i.e. Ball) or one of its base classes. class Ball : ExtendedEnum<Ball, String> // Valid {...} class TennisRacket : ExtendedEnum <Ball, String> // Invalid {...} class SpecializedBall : Ball // Valid {...} The underlying type exposed as an Enum through this class. Produces an array of all the Enum's members. Changing the returned array will not affect this ExtendedEnum type. Finds the ExtendedEnum member wrapping the given value. The value to find in this Enum. Either the found Enum member or null if no member is found. Determine if this ExtendedEnum type contains the given value. The value to try to find. true if value is found as a member of this Enum, false if not. Determine if this ExtendedEnum type contains the given value. The value to try to find. true if value is found as a member of this Enum, false if not. Converts from ExtendedEnum<T, U> to U. This is equivalent to calling UnderlyingValue. The ExtendedEnum member to convert. value's underlying value. Determine the equality of this ExtendedEnum member to another ExtendedEnum member. This is equivalent to calling UnderlyingValue.Equals(other.UnderlyingValue). The other value for comparison. true if this.UnderlyingValue.Equals(other.UnderlyingValue), false if not. Determine the equality of this ExtendedEnum member to another value. This is equivalent to calling UnderlyingValue.Equals(other). T value against which to compare this ExtendedEnum member. true if this.UnderlyingValue.Equals(other). Determine the equality of this ExtendedEnum member to another object. object against which to compare this ExtendedEnum member. Returns false if other is null. Returns true if other is referentially equal to this. Returns true if other is a U and this.Equals( (U)other ). Returns true if other is an ExtendedEnum<T, U> and this.Equals( (ExtendedEnum<T, U>)other ). Returns false otherwise. Get a hash code for this ExtendedEnum member. A hash code dependent on this enum type and on this enum member's Id. Compare this to another member of this ExtendedEnum, ordered according to their Ids. Other member against which to compare. <0 if this member is ranked first, 0 if they are the same member, and >0 if other should be ranked first. The underlying T value wrapped in this ExtendedEnum. Get the string representation for this ExtendedEnum member. Equivalent to calling UnderlyingValue.ToString(). The string representation for this ExtendedEnum member. Static constructor For the Ball example above, the static fields Ball.GolfBall, Ball.Basketball are initialized in the static constructor. According to the .Net specifications, a static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced. If clients would call: Ball.Values, before any field in Ball would be referenced (e.g. Ball.BasketBall.DoSomething()), then the Values array would be empty. This happens because the .Net compiler performs optimizations and does not call the derived class' (e.g. Ball) static constructor. It directly calls base.Values. To avoid this, we use reflection to reference a static field in the caller class which will trigger the call to the derived class' static constructor. Constructor intended for enumerations designating a certain set of instances from another type. This means that instances of the generic parameter U type can be constructed without labeling them as members of the enumeration. Also checks to see if the curiously recursive template pattern requirements are satisfied. U value to wrap as an ExtendedEnum member. The underlying T value wrapped by this ExtendedEnum instance. Provides the next Id value to assign to an Enum member added to the list. The next id is maintained in this counter instead of using sValues.Count to be future-proof against the possibility of removing Enum members from the list. The list of members in this Enum. Base class used to identify the classes that derive from ExtendedEnum Clients that want to identify which classes derive from the ExtendedEnum can do so, by looking for this base class. Constructor The id for each value in the ExtendedEnum Uses reflection to call the ExtendedEnum's Values property The ExtendedEnum class type An array containing all the ExtendedEnum's members. Uses reflection to call the static constructor. According to the .Net specifications a static constructor cannot be called directly. However, using reflections to artificially reference one of the class' static variables, its the static constructor will be automatically called. The class type whose static constructor needs to be called. Checks to see if the curiously recursive template pattern is being correctly implemented between the two class types. The derived type which should be or derive from the enumeratedType. The enumeratedType. The numerical Id for this ExtendedEnum within the enum's set. These Ids are used for ordering the members within the enum. ExtendedEnum id. This provides the ordering within the set. Class that inherits from ExtendedEnum, used for testing purposes Class that inherits from ExtendedEnum with 2 generic parameters This class extends standard ComponentResourceManager and adds the support to MultiIcon, Icon and Image resources. C++/CLI projects can manage a single instance of this class and use it to implement resource management for the assembly. By providing static methods accessing a single instance of this class, the resources management class may more closely resemble the designer-generated resource management classes in C# projects. Constructor. Construct a resource manager that looks up resources in satellite assemblies based on information from the specified type. A Type from which the resource manager derives all information for finding resource files. Get a MultiIcon resource from the assembly's set of resources. Key string used to identify the desired resource. The resource specified by the given key, or null if the resource is not found. Get an Icon resource from the assembly's set of resources. Key string used to identify the desired resource. The resource specified by the given key, or null if the resource is not found. Get an Image resource from the assembly's set of resources. Key string used to identify the desired resource. The resource specified by the given key, or null if the resource is not found. Empty class paired to ExtendedResourceManagerTestResources.resx to allow the resource manager instance in ExtendedResourceManagerTest to find the resources through a type. Test Class which inherits from an ExtendedEnum with 2 generic parameters. The second generic parameter is a complex type Test Class which inherits from an ExtendedEnum with 2 generic parameters. The second generic parameter is an integral type Test Class which inherits from an ExtendedEnum with 2 generic parameters. Used to test that ExtendedEnums built around the same underlying types (String) do not have the same values. Test Class which inherits from an ExtendedEnum with 2 generic parameters. Used to test that ExtendedEnums built around the same underlying types (String) do not have the same values. FileUtilities.SafeWrite passes control to this delegate to perform specific writing. Open stream to which the delegate may write. Note that the delegate should close this stream or any enclosing writer (e.g. StreamWriter) object to ensure that the output is flushed. FileUtilities.SafeWrite passes control to this delegate to perform validation of the temporary output file. If validation fails, original file if present remains, otherwise the original file is replaced by the temporary output file. The file name of the temporary file to validate. The file name of the temporary file to validate. true if the validation succeeded. FileUtilities.SafeWriteXml passes control to this delegate to perform specific writing. Open XmlWriter around an output stream. FileUtilities.SafeWriteText passes control to this delegate to perform specific writing. Open StreamWriter around an output stream. Class that contains useful file-related operations. Copies source file to destination and makes it writeable. The file to copy. The place to copy it to. Wraps a delegate write method to ensure that any exception thrown during the write process does not corrupt the original file. SafeWrite works by: Opening a FileStream on a temporary file with write permissions Passing the stream to the delegate to carry out the actual writing Moving the successfully written file to the actual destination path The WriteMethod must close any enclosing writer it creates, and the stream through that close, in order to guarantee that all its output is flushed to the file. Output location for the written file. Delegate to perform the specific writing. Wraps a delegate write method to ensure that any exception thrown during the write process does not corrupt the original file. SafeWrite works by: Opening a FileStream on a temporary file with write permissions Passing the stream to the delegate to carry out the actual writing Moving the successfully written file to the actual destination path The WriteMethod must close any enclosing writer it creates, and the stream through that close, in order to guarantee that all its output is flushed to the file. Output location for the written file. Delegate to perform the specific writing. Delegate to perform validation. Wraps a delegate write method to ensure that any exception thrown during the write process does not corrupt the original file. SafeWriteXml is a convenience method around SafeWrite for writing XML documents. It provides an XmlWriter to the delegate and ensures that the writer is flushed and closed after the delegate returns control. This version uses the default FileUtilities.XmlWriterSettings as the XmlWriter's settings. Output location for the written file. Delegate to perform the specific writing. Wraps a delegate write method to ensure that any exception thrown during the write process does not corrupt the original file. SafeWriteXml is a convenience method around SafeWrite for writing XML documents. It provides an XmlWriter to the delegate and ensures that the writer is flushed and closed after the delegate returns control. It also provides an validator to ensure the written file is readable as an xml doc Output location for the written file. Delegate to perform the specific writing. XmlWriterSettings to use in the XmlWriter Wraps a delegate write method to ensure that any exception thrown during the write process does not corrupt the original file. SafeWriteText is a convenience method around SafeWrite for writing text output. It provides a StreamWriter to the delegate and ensures that the writer is flushed and closed after the delegate returns control. Output location for the written file. Delegate to perform the specific writing. Recommended file settings for xml files written by the application. A IconDeviceIndependentBitmap stores a device independent bitmap (DIB). This class makes the loading and saving of *.ico files much easier. The format of the wrapped bitmap in IconDeviceIndependentBitmap is a little bit different with standard windows bitmap: It contains a "xor mask" and an "and mask". For more information about the icon DIB format, please reference msdn: http://msdn.microsoft.com/en-us/library/ms997538.aspx Construct an empty IconDeviceIndependentBitmap with the given width, height and color bit count. The width of the icon. This parameter must be ranged in [1, 255] The height of the icon. This parameter must be ranged in [1, 255] The color bit count of the icon. This parameter must be greater than 8 because we don't support palette colors for now. Throws if width or height is not ranged in [1, 255], or if colorBitCount is less than or equal to 8. Construct an IconDeviceIndependentBitmap from the given bitmap. The given bitmap. Throws if bitmap.Width or bitmap.Height exceeds 255, or if color bit count of the given bitmap is less than or equal to 8. Load an IconDeviceIndependentBitmap from the given stream. The given stream. Throws if the stream contains an invalid icon. Write this IconDeviceIndependentBitmap to the given stream. The given stream. Calculate the total bytes of a IconDeviceIndependentBitmap that will be stored in file, including the dib header (Notice the dib header is not icon file entry). The width of that dib. The height of that dib. The color bit count of that dib. The total bytes of that dib. Get the dib header size. The dib header size. Get the palette size of this dib. The palette size of this dib. Get the xor mask size. The xor mask size. Get the and mask size. The and mask size. Get the total bytes of a IconDeviceIndependentBitmap that will be stored in file, including the dib header. The width of this dib. The height of this dib. The color bit count of this dib. The xor mask array of this dib. In DEFAULT_COLOR_BIT_COUNT bit argb format. The and mask array of this dib. Each bit represents a pixel. Default color bit count of default pixel format. Default pixel format. Calculate the 4-bytes aligned byte count from the total bit count. total bit count. corresponding 4-bytes aligned size. In bytes. Calculate the 4-bytes aligned size of each line of the DIB. The width of the dib. The color bit count of the dib. The 4-bytes aligned size of each line of the dib. Get the DEFAULT_COLOR_BIT_COUNT-bit rgb array from a given bitmap. The given bitmap. The DEFAULT_COLOR_BIT_COUNT-bit rgb array of the bitmap. If the bitmap is other format, we performed a temporary format conversion. If the conversion failed, this function returns null. Create an empty "and mask" for this DIB. Calculate how many colors should be used in palette. The color bit count. How many colors should be used in palette. Get the size of bytes of each color entry in palette. The size of bytes of each color entry in palette. Get the size of bytes of color palette. How many colors are used? The size of bytes of color palette. Check if the input parameters are valid. true if the parameters are valid, false otherwise. Calculate the total bytes of this IconDeviceIndependentBitmap that will be stored in file, including the dib header (Notice the dib header is not icon file entry). Specifies the number of bytes required by the header structure. Specifies the width of the bitmap, in pixels. Specifies the height of the bitmap, in pixels. Specifies the number of planes for the target device. This value must be set to 1. Specifies the number of bits-per-pixel. This determines the xor mask format. Specifies the type of compression of this bitmap. This is always zero in our case because we don't handle compressed bitmaps. Specifies the size, in bytes, of the image. Including bitmap headers and palette. Specifies the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. An application can use this value to select a bitmap from a resource group that best matches the characteristics of the current device. Specifies the vertical resolution, in pixels-per-meter, of the target device for the bitmap. Specifies the number of color indexes in the color table that are actually used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the mColorBitCount member for the compression mode specified by mCompression. Specifies the number of color indexes that are required for displaying the bitmap. If this value is zero, all colors are required. The xor mask of this bitmap. Please see remarks of this class. The and mask of this bitmap. Please see remarks of this class. A utility class for converting Icon formats used in Windows Forms and WPF. Converts a Icon object (used by Windows Forms) into an ImageSource supported by WPF. A valid Icon object. An ImageSource object. This utility class is used for manipulating icons. Convert a bitmap to an GDI+ Icon (32bit color). The returned icon supports transparent color and alpha channel. This is much better than Icon.FromHandle(bitmap.GetHIcon()). If you used the Bitmap.GetHIcon, you must explicitly depose that handle by calling win32 api: DestroyIcon. However, using out method here you don't need to worry about GDI resource leak because we perform the conversion based on data stream but not on GDI handles. For more information, please reference: http://www.codeproject.com/dotnet/MultiIcon.asp Load all DIBs from the given stream, convert those DIBs to Icons, and then returns an array of those separate Icons. Stream containing one icon data. An icon file may contains a set of DIBs for displaying under different resolution. This function just separates those DIBs and converts each DIB into an Icon. Build an Icon from the given Icon specification information: the file header, entry specification data, and data stream. Header data from the icon file. Descriptor for the current icon entry to be extracted. Stream containing the icon data. A new Icon built from the given specification and data. Storage for the header information from the .ico file. The size of this structure. Construct from an Icon data stream. Construct from icon count. Write this header to a stream. Storage for entry information from the .ico file. The size of this structure. Construct from a bitmap and the index of this icon entry. Notice that the index starts from zero. Construct from an Icon data stream. Write this structure to a stream. Icon header information for individual Icons. Icon header information for individual Icons. A first-class object, bit masks and query functions for the DragEventArgs.KeyState and QueryContinueDragEventArgs.KeyState properties as defined in the msdn documentation. These aren't formalised anywhere in the .NET framework. Mask values taken from DragEventArgs.KeyState and QueryContinueDragEventArgs.KeyState properties as specified in the msdn documentation. Left mouse button bit field. Right mouse button bit field. Shift key bit field. Ctrl key bit field. Middle mouse button bit field. Alt key bit field. Constructor. Takes the bitfield from DragEventArgs.KeyState or QueryContinueDragEventArgs.KeyState. The bitfield from DragEventArgs.KeyState or QueryContinueDragEventArgs.KeyState. The encapsulated KeyState bit field. Determine if this KeyState is equal to another KeyState value. Two KeyStates are equal if they have exactly equal Bits. The object against which to compare. true if other is a KeyState and has exactly the same Bits as this. false otherwise. Get a hash code for this KeyState value. Hash code created from the Bits value. Is the left mouse button pressed? Is the right mouse button pressed? Is the middle mouse button pressed? Is the Shift key pressed? Is the Ctrl key pressed? Is the Alt key pressed? The encapsulated KeyState bit field. Collection of convenience methods for establishing data bindings in code. Construct and set a Binding from the given source property to the target DependencyProperty, using the default BindingMode. Source object. Path to the source property. Target object. Target DependencyProperty. BindingExpression for the newly established binding. Construct and set a Binding from the given source property to the target DependencyProperty, using the default BindingMode. Source object. Path to the source property. Target object. Target DependencyProperty. Converts from the source value to the target value. BindingExpression for the newly established binding. Construct and set a Binding from the given source property to the target DependencyProperty, using a specified BindingMode. Source object. Path to the source property. Target object. Target DependencyProperty. The desired BindingMode. BindingExpression for the newly established binding. Construct and set a Binding from the given source property to the target DependencyProperty, using a specified BindingMode. Source object. Path to the source property. Target object. Target DependencyProperty. Converts from the source value to the target value. The desired BindingMode. BindingExpression for the newly established binding. Construct and set a Binding from the given source property to the target DependencyProperty, using a specified BindingMode. Source object. Path to the source property. Target object. Target DependencyProperty. Converts from the source value to the target value. Parameter passed to the converter's Convert and ConvertBack methods. The desired BindingMode. BindingExpression for the newly established binding. Debugging class useful for finding memory leaks. If you think you are leaking instances of a class, but are having a hard time distinguishing valid instances from invalid ones in a memory profiler, create a reference to a MemoryMarker object from your leaked object at a point just before the object should terminate. For example, to find leaked instances of WPFCustomControls.MaxRibbonControl, we can add a reference to a new MemoryMarker during HandleUnloaded. We can then identify the roots for the leaked MaxRibbonControl instance by looking for the MemoryMarker instance. MultiIcon is a reader and container for icon resources. Although an .ico file may be authored to include multiple icons, the .NET Framework lacks any useful way to manage these files. This implementation is inspired by this article on CodeProject: http://www.codeproject.com/dotnet/MultiIcon.asp The .ico file format is documented there as well. CSharpUtilities.MultiIcon can be used as a ResXFileRef in a .resx file in C#, but it doesn't seem to work in C++/CLI. Until we solve that, the resource can be typed as a System.Byte[] in the resx file, and then the MultiIcon constructor will extract the icons from that array. Construct from a String specifying the path to the icon file. Path pointing to the chosen icon file. Construct from an object Stream holding the icons. Stream holding the icon data. Construct from an array of icons. Array of icons to package as a MultiIcon. Construct from a single bitmap. Single bitmap to package as a MultiIcon. Construct from a single Icon. Single icon to package as a MultiIcon. Finalizer. Sort icons in order of area The list of Icons contained in this MultiIcon. Get the largest Icon contained in this MultiIcon. The largest Icon size is determined by comparing the areas of each Icon. The largest Icon contained in this MultiIcon. Get the largest Icon index contained in this MultiIcon. The largest Icon size is determined by comparing the areas of each Icon. The largest Icon index contained in this MultiIcon, or -1 if empty. Get the largest Icon contained in this MultiIcon, converted to an Image. The largest Icon size is determined by comparing the areas of each Icon. This method is equivalent to ConvertIconToImage(GetLargestIcon()) The largest Icon contained in this MultiIcon, converted to an Image. Get the smallest Icon contained in this MultiIcon. The smallest Icon size is determined by comparing the areas of each Icon. The smallest Icon contained in this MultiIcon. Get the smallest Icon index contained in this MultiIcon. The smallest Icon size is determined by comparing the areas of each Icon. The smallest Icon index contained in this MultiIcon, or -1 if empty. Get the smallest Icon contained in this MultiIcon, converted to an Image. The smallest Icon size is determined by comparing the areas of each Icon. This method is equivalent to ConvertIconToImage(GetSmallestIcon()) The smallest Icon contained in this MultiIcon, converted to an Image. Get the largest Icon from this MultiIcon that fits within the given maximum Size. "Fits" means that Icon.Width <= maximumSize.Width and Icon.Height <= maximumSize.Height. The constraint size. The returned Icon must fit in this size. The largest icon from this MultiIcon that fits within maximumSize, or null if no such Icon is found. Get the largest Icon index from this MultiIcon that fits within the given maximum Size. "Fits" means that Icon.Width <= maximumSize.Width and Icon.Height <= maximumSize.Height. The constraint size. The returned Icon must fit in this size. The largest icon index from this MultiIcon that fits within maximumSize, or -1 if no such Icon is found. Get the largest Icon from this MultiIcon that fits within the given maximum Size, converted to an Image. "Fits" means that Icon.Width <= maximumSize.Width and Icon.Height <= maximumSize.Height. Equivalent to ConvertIconToImage(GetLargestIconNotLargerThan(maximumSize)). The constraint size. The returned Icon must fit in this size. The largest icon from this MultiIcon that fits within maximumSize, or null if no such Icon is found. Get the smallest Icon from this MultiIcon that completely covers the given minimum Size. Covering the minimum size means that minimumSize.Width <= Icon.Width and maximumSize.Height <= Icon.Height. The constraint size. Each of the icon's dimensions must be greater than or equal to the corresponding dimension from this Size. The smallest Icon from this MultiIcon that covers minimumSize, or null if no such Icon is found. Get the smallest Icon index from this MultiIcon that completely covers the given minimum Size. Covering the minimum size means that minimumSize.Width <= Icon.Width and maximumSize.Height <= Icon.Height. The constraint size. Each of the icon's dimensions must be greater than or equal to the corresponding dimension from this Size. The smallest Icon index from this MultiIcon that covers minimumSize, or -1 if no such Icon is found. Get the smallest Icon from this MultiIcon that completely covers the given minimum Size, converted to an Image. Covering the minimum size means that minimumSize.Width <= Icon.Width and maximumSize.Height <= Icon.Height. This method is equivalent to ConvertIconToImage(GetSmallestIconNotSmallerThan(minimumSize)). The constraint size. Each of the icon's dimensions must be greater than or equal to the corresponding dimension from this Size. The smallest Icon from this MultiIcon that covers minimumSize, or null if no such Icon is found. Calculates the size of the icon according to dpi and returns the downscaled icon. This function does not upscale the original icon, make sure the icon supports a size big enough to cover specific dpi. If there isn't an icon large enough to cover desired dpi, the largest icon available is returned. Assumes that the base image size is 16x16 at 100% dpi, for a more customizable function, use GetDPIAwareIcon(int refWidth, int refHeight) The scaled icon. Calculates the size of the icon according to dpi and returns the downscaled icon index. This function does not upscale the original icon, make sure the icon supports a size big enough to cover specific dpi. If there isn't an icon large enough to cover desired dpi, the largest icon available is returned. Assumes that the base image size is 16x16 at 100% dpi, for a more customizable function, use GetDPIAwareIcon(int refWidth, int refHeight) The scaled icon index, or -1 if you need to compute it. Calculates the size of the icon according to dpi and returns the downscaled icon. This function does not upscale the original icon, make sure the icon supports a size big enough to cover specific dpi. If there isn't an icon large enough to cover desired dpi, the largest icon available is returned. image width at 100% dpi. If refWidth is equal -1, the width of the smallest image available in the ico file is considered. image height at 100% dpi. If refHeight is equal -1, the height of the smallest image available in the ico file is considered. The scaled icon. Calculates the size of the icon according to dpi and returns the downscaled icon index. This function does not upscale the original icon, make sure the icon supports a size big enough to cover specific dpi. If there isn't an icon large enough to cover desired dpi, the largest icon available is returned. image width at 100% dpi. If refWidth is equal -1, the width of the smallest image available in the ico file is considered. image height at 100% dpi. If refHeight is equal -1, the height of the smallest image available in the ico file is considered. The scaled icon index or -1 if you need to compute it. Calculates the size of the icon according to dpi and returns the downscaled icon converted to image. This function does not upscale the original icon, make sure the icon supports a size big enough to cover specific dpi. The scaled image. Converts the given Icon to a bitmap image. Icon to convert to an Image. Image created from the given icon. Scales the given Icon to finalSize, producing a new Icon instance. The original Icon to resize. This Icon instance will not be affected. The desired final size for the resulting scaled Icon. A new Icon, created by scaling the originalIcon to finalSize. Load all Icons from the file specified by the given path. Traps any thrown exceptions. Load PNG Icons from the specified filepath. if filepath= Directory/filename.png, it loads all files that are: directory/filename_XX.png. Check wether specified file is png by testing the extension file name with or without path True if file extension is png. False otherwise. Helper IComparer class for comparing two Sizes by area. Compare the two given Sizes by area. left hand side operand right hand side operand Less than zero if lhs is less than rhs. Zero if lhs and rhs equal. Greater than zero if lhs is greater than rhs. Helper IComparer class for comparing two Icon Sizes by area. Compare the two given Icon Sizes by area. left hand side operand right hand side operand Less than zero if lhs is less than rhs. Zero if lhs and rhs equal. Greater than zero if lhs is greater than rhs. Determine if the lhs Size is absolutely <= the rhs Size. That is, lhs.Width <= rhs.Width and lhs.Height <= rhs.Height. Left hand side operand. Right hand side operand. true if lhs is less than or equal to rhs. false otherwise. Determine if the lhs Size is absolutely >= the rhs Size. That is, lhs.Width >= rhs.Width and lhs.Height >= rhs.Height. Left hand side operand. Right hand side operand. true if lhs is greater than or equal to rhs. false otherwise. Share a single empty list for all empty MultiIcons. The list of Icons contained in this MultiIcon. Fills the image icon cache with images. Share a single empty list for all empty cached icon images. The list of Icons contained in this MultiIcon. Generic Pair structure, often useful for keeping ordered lists of associated objects. Type for the first item in the pair. Type for the second item in the pair. Constructor. First item Second item The first item in the Pair. The second item in the Pair. Get a hash code for this object. A hash code for this object. Determine if this Pair is equal to the passed in Object. Object to evaluate for equality with this Pair. true if this Pair is equal to the passed in Object. The first item in the Pair. The second item in the Pair. Ordered associative list. Type of the first item in each Pair. Type of the second item in each Pair. Produce a List of the just the First items from each Pair in this PairList. A List of the just the First items from each Pair in this PairList. Produce a List of the just the Second items from each Pair in this PairList. A List of the just the Second items from each Pair in this PairList. Encapsulates arguments for KeyDown, KeyUp and KeyPress .NET events for events that may “bubble up” the source component's parent chain. This is simply a convenience class whose main role is to allow for the exposure of multiple key events via a single event. This helps in situations where we're interested in bubbling up all significant key events without having to expose three new events on each parent component through which the bubbling occurs. Corresponds to the KeyUp, KeyDown and KeyPress events in the Win32 API. These enum values have purposefully been set to match the corresponding Windows Message values (WM_KEYDOWN, WM_KEYUP, and WM_CHAR). Key Down event bit mask. Key Up event bit mask. Key Press bit mask (Down and then Up). Constructor taking an event enum value and event args value. The key event type for this routed event. Arguments passed to event listeners. The key event type for this routed event. Event arguments intended for event listeners. The key event type for this routed event. Event arguments intended for event listeners. Collection of distinct objects. Items in a Set are unique within the Set according to the EqualityComparer used. Set is implemented in terms of a Dictionary<T, Object>, so its performance matches that of Dictionary<T, Object>. Type of the Set's items. Construct an empty Set using the default equality comparer and default capacity. The default equality comparer is EqualityComparer<T>.Default. Using a constructor to specify a capacity may improve efficiency by avoiding resizing while adding any initial objects. Construct an empty Set with a given minimum capacity, and using the default equality comparer. The default equality comparer is EqualityComparer<T>.Default. Using a constructor to specify a capacity may improve efficiency by avoiding resizing while adding any initial objects. The number of elements that can be added before resizing is necessary. Construct a Set from a collection of items, using the default equality comparer. The default equality comparer is EqualityComparer<T>.Default. Initial collection of items to add to this Set. Since the Set is guaranteed to contain unique items, any duplicate items in the collection will be ignored. Construct an empty Set with a specific equality comparer, using the default capacity. Used when comparing items. Every item in the Set is unique according to this comparer. Construct an empty Set with a given capacity and a specific equality comparer. The number of elements that can be added before resizing is necessary. Used when comparing items. Every item in the Set is unique according to this comparer. Construct a Set from a collection of items, using a specific comparer. Initial collection of items to add to this Set. Since the Set is guaranteed to contain unique items, any duplicate items in the collection will be ignored. Used when comparing items. Every item in the Set is unique according to this comparer. Construct a new Set with the same items and comparer as an existing Set. Set to copy. Adds an item to the Set. If this.Contains(item), item is ignored. Item to add. Adds all items in a given collection to this set. Any duplicate items in items and any items already in this Set will be ignored. Collection of items to add. Removes all items from this Set. Determines if this Set contains the given item. Item to locate in this Set. true if the item is in this Set. false otherwise. Copies all of the items in this Set to the given array, starting at the specified base index in the array. Destination one-dimensional array into which this Set's items will be copied. Starting index in the destination array at which to begin copying elements. Throws if array.Length - baseIndex < this.Count. Throws if baseIndex < 0 Throws if array is null. Used to determine the equality of items in this Set. The current number of items in this Set. Removes an item from this Set. If the item is not a member of this Set, this Set remains unchanged. Item to remove from this Set. true if an item was removed. false if the item was not present. Get an Enumerator for iterating over this Set's items. An Enumerator for iterating over this Set's items. Replaces the current Set with the union of this Set and the given collection. After applying Union, this Set will have all the original items from this Set, and all distinct items from the passed in collection. Collection of items to unite with this Set. Replaces the current Set with the intersection of this Set and the given collection. After applying Intersection, this Set will contain all distinct items that exist in both this original Set and in the given collection. Collection of items to intersect with this Set. Removes all items in the given collection from this Set. Any items in the given collection that are not presented in this Set are ignored. Collection of items to remove from this Set. Is this collection read-only? Always false. Copies all of the items in this Set to the given array, starting at the specified base index in the array. Destination one-dimensional array into which this Set's items will be copied. Starting index in the destination array at which to begin copying elements. Throws if array.Length - baseIndex < this.Count. Throws if baseIndex < 0 Throws if array is null. Indicates whether access to the collection is thread-safe. Object used to synchronize access to the collection. Backing storage for this Set's elements. For convenience, a Dictionary is used, but the Value elements are ignored. A very simple abstract command which supplies a default implmentation for CanExecute, as well as a RaiseCanExecuteChanged method. Return true by default. The parameter to the command. true, by default Part of the ICommand interface A method for notifying interested parties that the value of CanExecute has potentially changed. Entry point for command execution. parameter to the command Test Class which inherits from an ExtendedEnum with a single generic parameter. Test Class which inherits from an ExtendedEnum with a single generic parameter. Used to test if the Extended enum's static constructor will successfully invoke this class' static constructor. A value converter that simply calls Trim() on a string value. Convert a String to its Trim()-ed version. Implementation of interface method. The String to convert. The String type. A conversion parameter (should be empty.) The current system culture. The trimmed string. Not implemented, as it is impossible to untrim a trimmed string. empty empty empty empty Throws an exception if used. Useful general utilites for working with strings. Joins the string representations of all Items in a list, separated by a delimiter, into a single string. Works like System.String.Join, except on a list of arbitrary objects. Each item the list is transformed into a string using ToString, and then these string representations are joined as with System.String.Join. String placed between each individual item in the list. List of objects whose string representations will be joined. A single string composed of the string representations of all Items in list, separated by delimiter. P/Invokes native method for string ordering like in Windows Explorer. Compares two Unicode strings. Digits in the strings are considered as numerical content rather than text. This test is not case sensitive. Using P/Invoke here and letting the platform deal with marshalling the strings in much simpler than trying to do everything manually. A pointer to the first null-terminated string to be compared. A pointer to the second null-terminated string to be compared. Returns zero if the strings are identical. Returns 1 if the string pointed to by psz1 has a greater value than that pointed to by psz2. Returns -1 if the string pointed to by psz1 has a lesser value than that pointed to by psz2. Convert the a string to a hash with UTF8 Encoding A string which will be transformed into a hash Returns an integer with a hash value Replaces the standard BackgroundWorker provided by the .NET Framework to fix what seems to be a bug causing the BackgroundWorker to fire events in the wrong thread. We have encountered cases where the BackgroundWorker seems to lose track of the main thread or just arbitrarily decide to fire ProgressChanged and RunWorkerCompleted in a new thread rather than in the main thread. This causes synchronization errors. This replacement class allows the client to specify a ISynchronizeInvoke synchronizer object through which the events will be fired. All Controls implement ISynchronizeInvoke, so any Control should be adequate to act as a synchronizer to invoke the events in the main thread. The synchronizing context. If this object is given a Synchronizer, ProgressChanged and RunWorkerCompleted events will occur in the Synchronizer's thread. Overrides the base OnProgressChanged to invoke ProgressChanged events in the Synchronizer's thread. EventArgs containing data for ProgressChanged listeners. Overrides the base OnRunWorkerCompleted to invoke RunWorkerCompleted events in the Synchronizer's thread. EventArgs containing data for RunWorkerCompleted listeners. Delegate type for ProgressChanged. EventArgs containing data for ProgressChanged listeners. Delegate type for RunWorkerCompleted. EventArgs containing data for RunWorkerCompleted listeners. The synchronizing context. If this object is given a Synchronizer, ProgressChanged and RunWorkerCompleted events will occur in the Synchronizer's thread. Utility class helps unit tests find their data files, encapsulating the different search schemes required on dev machines and on automation machines. Holds a collection of found pathnames. For developers writing tests, the convention is to put data files in a TestData folder next to the source code, inside the project's folder. For example: \3dswin\src\dll\WeatherData\TestData. When running unit tests inside a developer build (so in src\exe or src\x64\exe), the data in this location should be found automatically. After the build is produced on a build machine, all TestData folders in the source code are packaged up in a zip file. When the automation machines run the unit tests, they unzip this package and set up the environment so that this class can find the data by searching in the following locations: Inside the build, below a TestData directory, with subdirectories organized to match the source branch. Below a directory indicated by a UNIT_TEST_DATA environment variable, again with subdirectories organized to match the source branch. Instantiate this class with a basic glob pattern indicating the expected location for the files under 3dswin\src. Contains static utility methods related to UI and drawing. Determine if the given point is a valid screen location according to the current monitor setup. The screen location to examine. true if aLocation is a valid screen location, false otherwise EventArgs type indicating that a value has already changed from and old value to a new value. Contains the old and new values as properties. Type of the changed value Construct from the old and new value. The previous value for the changed property or variable. The new current value for the changed property or variable. Abstract value change event args. Serves as a base class for the more specific derived types The type of the value for which a change Default constructor. Uses null values for OldValue and NewValue. Construct with old and new values. The original value The value to which the data has changed or will change. The original value for the changed or changing data. The new value for the changed or changing data. The original value for the changed or changing data. The new value for the changed or changing data. EventArgs containing data for signalling that a data value will change value. Type of the changing data value. Construct with an old and new value. The current (old) value. The new value to which the data value will change. Handlers may use this property to control whether the value will be permitted to change, Handlers may use this property to control whether the value will be permitted to change, Encapsulates safely temporarily setting a variable value while some operation is performed. VariableGuard safely encapsulates the following implementation pattern: 1. Set a variable to a given value while performing an operation 2. Perform the operation 3. Set the variable back to its original value For example, to disable event handlers in a class, we might write: EventHandler oldHandlers = SomeEvent; SomeEvent = null; DoOperation(arg1, arg2); // arg1 and arg2 are local variables SomeEvent = oldHandlers. Unfortunately, this isn't particularly safe since any exception thrown in DoOperation will leave SomeEvent disabled. We need a try/finally block to prevent this deleterious side-effect. This class encapsulates the pattern in a single call. Using an anonymous delegate, which is bound to its calling environment (a closure), the client code can invoke this guard using: VariableGuard.Guard( SomeEvent, null, delegate { DoOperation(arg1, arg2); } ); Delegate type for the delegate passed to the Guard method below. Temporarily set variable to value while calling the guardedCode delegate. See the class documentation for more information. variable's type reference parameter pointing to the variable to temporarily modify. the value to which to set the variable during the operation the operation delegate to call while variable is set to value. Maintains a list of event handlers through weak references. WeakEvent is intended for use as the backing storage for an event. Note that WeakEvents invoke handlers through reflection and so are slower than standard events. A WeakEvent is intended for cases where leaks are especially likely to occur, such as for events published from a singleton object. Example code for the publishing class: class MyClass { public event EventHandler MyEvent { add { WeakMyEvent.AddHandler(value) }; remove { WeakMyEvent.RemoveHandler(value) }; } protected virtual void OnMyEvent(EventArgs e) { WeakMyEvent.Raise(this, e); } private readonly WeakEvent WeakMyEvent = new WeakEvent(); } Event listeners add and remove themselves from such events as they would for any standard event. Add a handler, maintained by weak reference, to the list of event handlers for this event. Event handler Remove an event handler from this event. Event handler Raise this event, triggering any registered event handlers whose WeakReferences have not been collected. Source object for this event. Information about the event. Serves instead of a standard event handler to avoid maintaining a strong reference to the handler target causing a possible memory leak. Construct from an event handler Delegate. Event handler. WeakReference to the listening object. The handler method. Is the WeakReference target still alive? Invokes this event handler. Does not check if the TargetReference is alive. It is up to the caller to check IsAlive first. Function arguments to pass to the event listener. General utility methods for working with WPF. Allows all pending Dispatcher messages to be processed before continuing. Avoid overuse of this method. Generally, WPF does a better job of managing message processing priorities than this brute-force approach. Convert a point from WPF's device independent units to pixels based on the Visual's presenter's DPI setting. WPF point to convert. Visual providing the DPI setting. The point converted to pixel coordinates. Convert a Rect from WPF's device independent units to pixels based on the Visual's presenter's DPI setting. WPF Rect to convert. Visual providing the DPI setting. The Rect converted to pixel coordinates. Convert a point from pixels to WPF's device independent units based on the Visual's presenter's DPI setting. Point in pixel coordinates to convert. Visual providing the DPI setting. The point converted to WPF's device independent units. Convert a Rect from pixels to WPF's device independent units based on the Visual's presenter's DPI setting. Rect in pixel coordinates to convert. Visual providing the DPI setting. The Rect converted to WPF's device independent units. Get the current device transform, used to apply DPI settings among other things, for rendering the given Visual. Visual with the desired rendering context. Render transform matrix used for the given visual. P/Invokes GetWindowRect from the Windows API. IntPtr wrapping the native window handle. Out parameter returning the dimensions of the native window. nonzero on success, 0 on failure Data type created for marshalling to a Windows API RECT. Represents a window's dimensions in pixels. X-coordinate of the window's left edge. Y-coordinate of the window's top edge. X-coordinate of the window's right edge. Y-coordinate of the window's bottom edge. Gets a native window's location and dimensions in pixels. Handle to the native window. The native window's location and dimensions in pixels. Centers a WPF Window to a native Win32 owner window. For centering a WPF Window to a WPF owner window, it suffices to set Window.WindowStartupLocation to CenterOwner. Unfortunately, this does not work when centering a WPF window on a native owner, at least when the owner is maximized. To center a Window at its startup, call CenterWindowToNativeOwner from a Window.SourceInitialized event handler. CenterWindowToNativeOwner requires the Window's HwndSource and Visual to have been created in order to translate to Device Independent Units. Window to center Given a UIElement, turns on the Display-style text rendering for this sub-tree of components. Certain projects need to target the .NET 3.5 SDK. .NET 4.0 introduced a crucial WPF feature: better rendering for small (less than or equal to 12pt) fonts, which mimics typical text rendering in Win32. Since 3ds Max runs on the 4.0 platform (at a minimum) we can turn this feature on dynamically, using reflection. Projects that target 4.0 should add the attached property (TextOptions.TextFormattingMode = TextFormattingMode.Display) directly, using standard mechanisms. This method is purely for projects that don't have the option to target the 4.0 framework directly. The element for which Display-style formatting should be turned on. Looks up caches the reflection types needed in TurnOnSharpTextRendering(UIElement). A static class which defines two useful attached properties: BindableToolTip.DataContext and BindableToolTip.ToolTip This class bypasses a very annoying trait of WPF, which is that the PlacementTarget of a Popup (which includes ToolTips) indirectly sets the DataContext of the element to be inherited context from the Target. This is very counter-intuitive, especially from the logical definition standpoint, but it as a result of how the Visual tree is calculated. This class allows you define the DataContext for a tooltip more explicitly. Given that this class is declared in the "CSharpWpf" Xaml namespace: <SomeControl ToolTipService.PlacementTarget="{Binding ElementName=SomeOtherElement}" CSharpWpf:BindableToolTip.DataContext="{Binding}" > <CSharpWpf:BindableToolTip.ToolTip> <ToolTip Content={Binding SomeMVVMPath} /> </CSharpWpf:BindableToolTip.ToolTip> </SomeControl> The result of this will be a tooltip who's DataContext is set to the context of SomeControl, and not the DataContext of the element named "SomeOtherElement". This allows you to bind Tooltip content or other properties relative to the logical context. Attached Property ToolTip declaration Attached Property mutator for ToolTip. The element on which the property value is being set. The value to set. Attached Property accessor for ToolTip. The element for which the property value is being retrieved. The value of the property for the given element. Attached Property DataContext declaration Attached Property mutator for DataContext. The element on which the property value is being set. The value to set. Attached Property accessor for DataContext. The element for which the property value is being retrieved. The value of the property for the given element. A factory for generating attached properties that link specific routed events to ICommands. Generates an attached dependency property for a class that can be used to hook up a specific event to a specific ICommand. RoutedEvent declaration to listen for. The name of ths property to create. The owning class of this generated property. An attached property declaration that has been registered correctly. An internal class to handle listening for an event and executing a command, when a Command is assigned to a particular DependencyProperty Handles attaching or Detaching Event handlers when a Command is assigned or unassigned Listens for a change in the DependencyProperty that we are assigned to, and adjusts the EventHandlers accordingly A collection of useful Mouse utility functions Get the absolute mouse position using the native Win32 SDK The absolute mouse position on screen in pixels An extension of ObservableCollection which supports range adding and deleting with only a single notification sent. Overriden to only raise notifications when notifications are not suppressed. event args Add a list of items to the collection. Only one notification will be made at the end of the addition (NotifyCollectionChangedAction.Reset). A list to add to the tail end of the collection. Remove a list of items to the collection. Only one notification will be made at the end of the removal (NotifyCollectionChangedAction.Reset). Not the the list of items do not need to be sequential. Each item passes through the Remove(T) function. A list to add to the tail end of the collection.