14 template<
typename T,
typename I>
17 if (i->QueryInterface(winrt::guid_of<T>(), winrt::put_abi(t)) == S_OK) {
32 winrt::event_token operator()(T
const& handler) {
33 return m_handler.add(handler);
35 auto operator()(
const winrt::event_token& token)
noexcept {
return m_handler.remove(token); }
37 template<
typename... TArgs>
38 auto invoke(TArgs&&... args) {
39 return m_handler(args...);
42 winrt::event<T> m_handler;
50 struct XamlEvent : cppxaml::details::XamlEvent_t<winrt::Windows::Foundation::EventHandler<T>> {};
62 template<
typename TSender,
typename TArgs>
63 struct TypedXamlEvent : cppxaml::details::XamlEvent_t<winrt::Windows::Foundation::TypedEventHandler<TSender, TArgs>> {};
81 auto PropertyChanged(cppxaml::xaml::Data::PropertyChangedEventHandler
const& value) {
82 return m_propertyChanged.add(value);
84 void PropertyChanged(winrt::event_token
const& token) {
85 m_propertyChanged.remove(token);
88 return *
static_cast<Type*
>(
this);
113 return m_propertyChanged(self(), cppxaml::xaml::Data::PropertyChangedEventHandler{name});
116 winrt::event<cppxaml::xaml::Data::PropertyChangedEventHandler> m_propertyChanged;
118 template<
typename TProperty>
129 T operator()()
const {
132 void operator()(
const T& value) {
148 template<
typename... TArgs>
149 XamlProperty(TArgs&&... args) : m_value(std::forward<TArgs>(args)...) {}
164 T operator()()
const {
168 void operator()(
const T& value) {
169 if (value !=
operator()()) {
172 (*m_npc)(m_sender, cppxaml::xaml::Data::PropertyChangedEventArgs{ m_name });
176 template<
typename... TArgs>
178 winrt::event<cppxaml::xaml::Data::PropertyChangedEventHandler>* npc,
179 winrt::Windows::Foundation::IInspectable sender,
180 std::wstring_view name,
192 winrt::event<cppxaml::xaml::Data::PropertyChangedEventHandler>* m_npc;
193 winrt::Windows::Foundation::IInspectable m_sender;
201#define INIT_PROPERTY(NAME, VALUE) \
202 NAME(&m_propertyChanged, winrt::try_as<winrt::Windows::Foundation::IInspectable>(this), std::wstring_view{ L#NAME }, VALUE)
The main CppXAML namespace.
Helper base class to inherit from to have a simple implementation of INotifyPropertyChanged.
Definition: XamlProperty.h:78
auto RaisePropertyChanged(std::wstring_view name)
Raises a property change notification event.
Definition: XamlProperty.h:112
A default event handler that maps to Windows.Foundation.TypedEventHandler.
Definition: XamlProperty.h:63
A default event handler that maps to Windows.Foundation.EventHandler.
Definition: XamlProperty.h:50
Implements a simple property (without change notifications).
Definition: XamlProperty.h:127
Implements a property type with notifications.
Definition: XamlProperty.h:161