/***************************************************************************** * DependencyProperty.h * * * * System::Windows::DependencyProperty definition file * * Copyright (c) XFX Team. All rights reserved * *****************************************************************************/ #ifndef _SYSTEM_WINDOWS_DEPENDENCYPROPERTY_ #define _SYSTEM_WINDOWS_DEPENDENCYPROPERTY_ #include #include "PropertyMetaData.h" using namespace System::Collections::Generic; namespace System { namespace Windows { /** * Represents a dependency property that is registered with the dependency property system. Dependency properties provide support for value expressions, data binding, animation, and property change notification. */ template class DependencyProperty { private: static Dictionary > _registeredProperties; DependencyProperty(const String& propertyName, const Type& type, T defaultValue) : DefaultValue(defaultValue), Name(propertyName) { } public: const T DefaultValue; const String Name; /** * Registers a dependency property with the specified property name and owner type. * * @param propertyName * The name of the dependency property to register. * * @param type * The owner type that is registering the dependency property. * * @return * A dependency property identifier that should be used to set the value of a public static readonly field in your class. The identifier is then used both by your own code and any third-party user code to reference the dependency property later, for operations such as setting its value programmatically, or attaching a System::Windows::Data::Binding in code. */ static DependencyProperty Register(const String& propertyName, const Type& type); /** * Registers a dependency property with the specified property name, owner type, and property metadata for the property. * * @param propertyName * The name of the dependency property to register. * * @param type * The owner type that is registering the dependency property. * * @param * A PropertyMetadata instance. This can contain a System::Windows::PropertyChangedCallback implementation reference. * * @return * A dependency property identifier that should be used to set the value of a public static readonly field in your class. The identifier is then used both by your own code and any third-party user code to reference the dependency property later, for operations such as setting its value programmatically, or attaching a System::Windows::Data::Binding in code. */ static DependencyProperty Register(const String& propertyName, const Type& type, PropertyMetadata const * propertyMetadata); }; /////////////////////////////////////////////////////////////////////// template DependencyProperty DependencyProperty::Register(const String& propertyName, const Type& type) { return Register(propertyName, type, new PropertyMetadata(null)); } template DependencyProperty DependencyProperty::Register(const String& propertyName, const Type& type, PropertyMetadata const * propertyMetaData) { _registeredProperties.Add(type, Dictionary()); _registeredProperties[type].Add(propertyName, propertyMetaData->DefaultValue); return DependencyProperty(propertyName, type, propertyMetaData->DefaultValue); } } } #endif //_SYSTEM_WINDOWS_DEPENDENCYPROPERTY_