-
I am trying to implement a simple data binding with INotifyPropertyChanged to refresh GUI when when value changed.
MainWindow.xaml.h: namespace winrt::App::implementation {
struct MainWindow : MainWindowT<MainWindow>, Microsoft::UI::Xaml::Data::INotifyPropertyChanged {
MainWindow();
public:
int32_t MyValue();
void MyValue(int32_t newValue);
winrt::event_token PropertyChanged(Microsoft::UI::Xaml::Data::PropertyChangedEventHandler const& handler);
void PropertyChanged(winrt::event_token const& token);
private:
int32_t myValue;
winrt::event<Microsoft::UI::Xaml::Data::PropertyChangedEventHandler> propertyChanged;
}
} MainWindow.xaml.cpp: void MainWindow::MyValue(int32_t newValue) {
if (myValue != newValue) {
myValue = newValue;
propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"MyValue" });
}
}
winrt::event_token MainWindow::PropertyChanged(Microsoft::UI::Xaml::Data::PropertyChangedEventHandler const& handler) {
return propertyChanged.add(handler);
}
void MainWindow::PropertyChanged(winrt::event_token const& token) {
propertyChanged.remove(token);
} MainWindow.xaml: <TextBlock Text="{x:Bind MyValue, Mode=OneWay}" /> But I got errors like:
How to solve it? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
winrt::eventMicrosoft::UI::Xaml::Data::PropertyChangedEventHandler propertyChanged = {nullptr}; |
Beta Was this translation helpful? Give feedback.
-
@RealTommyKlein can you help here, please? Here you can find a repro: |
Beta Was this translation helpful? Give feedback.
-
Thanks Tommy! Doing these two things fix the issues. @sxlllslgh I have updated the repro so you can see it working: https://github.com/marb2000/BasicBindingCpp |
Beta Was this translation helpful? Give feedback.
@RealTommyKlein can you help here, please? Here you can find a repro:
https://github.com/marb2000/BasicBindingCpp