2013-06-12 19:21:00 +02:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* DependencyProperty.h *
|
|
|
|
|
* *
|
|
|
|
|
* System::Windows::DependencyProperty definition file *
|
|
|
|
|
* Copyright (c) XFX Team. All rights reserved *
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
#ifndef _SYSTEM_WINDOWS_DEPENDENCYPROPERTY_
|
|
|
|
|
#define _SYSTEM_WINDOWS_DEPENDENCYPROPERTY_
|
|
|
|
|
|
|
|
|
|
#include <System/Collections/Generic/Dictionary.h>
|
|
|
|
|
#include "PropertyMetaData.h"
|
|
|
|
|
|
|
|
|
|
using namespace System::Collections::Generic;
|
|
|
|
|
|
|
|
|
|
namespace System
|
|
|
|
|
{
|
|
|
|
|
namespace Windows
|
|
|
|
|
{
|
2013-07-11 17:25:49 +02:00
|
|
|
|
/**
|
2013-07-12 21:30:13 +02:00
|
|
|
|
* 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.
|
2013-07-11 17:25:49 +02:00
|
|
|
|
*/
|
2013-06-12 19:21:00 +02:00
|
|
|
|
template <typename T>
|
|
|
|
|
class DependencyProperty
|
|
|
|
|
{
|
|
|
|
|
private:
|
2013-07-22 01:38:59 +02:00
|
|
|
|
static Dictionary<Type, Dictionary<String, Object *> > _registeredProperties;
|
2013-06-12 19:21:00 +02:00
|
|
|
|
|
2013-07-12 21:30:13 +02:00
|
|
|
|
DependencyProperty(const String& propertyName, const Type& type, T defaultValue)
|
2013-07-11 17:25:49 +02:00
|
|
|
|
: DefaultValue(defaultValue), Name(propertyName)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-12 19:21:00 +02:00
|
|
|
|
public:
|
2013-07-11 17:25:49 +02:00
|
|
|
|
const T DefaultValue;
|
|
|
|
|
const String Name;
|
|
|
|
|
|
2013-07-12 21:30:13 +02:00
|
|
|
|
/**
|
|
|
|
|
* 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<EFBFBD>static<EFBFBD>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<T> Register(const String& propertyName, const Type& type);
|
|
|
|
|
/**
|
|
|
|
|
* Registers a dependency property with the specified property name, owner type, and property metadata for the property.
|
|
|
|
|
*
|
2013-10-07 12:10:17 +02:00
|
|
|
|
* @param propertyName
|
2013-07-12 21:30:13 +02:00
|
|
|
|
* 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.
|
|
|
|
|
*
|
2013-10-07 12:10:17 +02:00
|
|
|
|
* @return
|
2013-07-12 21:30:13 +02:00
|
|
|
|
* A dependency property identifier that should be used to set the value of a public<EFBFBD>static<EFBFBD>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<T> Register(const String& propertyName, const Type& type, PropertyMetadata<T> const * propertyMetadata);
|
2013-06-12 19:21:00 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2013-07-12 21:30:13 +02:00
|
|
|
|
DependencyProperty<T> DependencyProperty<T>::Register(const String& propertyName, const Type& type)
|
2013-06-12 19:21:00 +02:00
|
|
|
|
{
|
2013-07-22 01:38:59 +02:00
|
|
|
|
return Register(propertyName, type, new PropertyMetadata<T>(null));
|
2013-06-12 19:21:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2013-07-12 21:30:13 +02:00
|
|
|
|
DependencyProperty<T> DependencyProperty<T>::Register(const String& propertyName, const Type& type, PropertyMetadata<T> const * propertyMetaData)
|
2013-06-12 19:21:00 +02:00
|
|
|
|
{
|
2013-07-22 01:38:59 +02:00
|
|
|
|
_registeredProperties.Add(type, Dictionary<String, T>());
|
2013-07-11 17:25:49 +02:00
|
|
|
|
_registeredProperties[type].Add(propertyName, propertyMetaData->DefaultValue);
|
|
|
|
|
|
|
|
|
|
return DependencyProperty<T>(propertyName, type, propertyMetaData->DefaultValue);
|
2013-06-12 19:21:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif //_SYSTEM_WINDOWS_DEPENDENCYPROPERTY_
|