Today, creating a custom dependency property requires a lot of boilerplate. This change gets rid of most of it. With this change, you can add a new dependency property quickly:
// .h
namespace winrt::BgLabelControlApp::implementation
{
struct BgLabelControl : BgLabelControlT<BgLabelControl>
{
// ...
// At some point in your app initialization, you want to call `BgLabelControl::EnsureLabelProperty`
WIL_DEFINE_DP(BgLabelControl, Label, winrt::hstring);
};
}
(If you want to be correct) .cpp: In your app, initialize the static DP during startup
.h: Declare & define member getter & setter functions
What changed?
Introduce new macros WIL_DEFINE_DP and WIL_DEFINE_DP_WITH_DEFAULT_VALUE_AND_CALLBACK that automatically create idiomatic implementations of the 3 static & member methods needed for a dependency property.
To avoid any problems with statics, these macros use function-local static storage instead of global static storage.
Today, creating a custom dependency property requires a lot of boilerplate. This change gets rid of most of it. With this change, you can add a new dependency property quickly:
Versus before you'd have to (see example on MSDN):
What changed?
WIL_DEFINE_DP
andWIL_DEFINE_DP_WITH_DEFAULT_VALUE_AND_CALLBACK
that automatically create idiomatic implementations of the 3 static & member methods needed for a dependency property.How tested?