Я новичок в программировании для настольных компьютеров Windows, Winui 3 и только что вернулся к C++ после того, как не программировал на нем несколько лет. Я работаю в Visual Studio, и большая часть этого кода генерируется.
У меня есть настольное приложение, которое не отображает главное окно, но ему необходимо периодически отображать диалоговое окно, чтобы получить подтверждение от Пользователь. Я определил диалоговое окно содержимого внутри MainWindow.xaml.
Код: Выделить всё
Dummy Content
Код: Выделить всё
::winrt::Microsoft::UI::Xaml::Controls::ContentDialog _consentDialog{nullptr};
::winrt::Microsoft::UI::Xaml::Controls::ContentDialog consentDialog()
{
return _consentDialog;
}
window = make();
but don't activate the window.
Later as the app is running under a background thread, I need to be able to display the ContentDialog. If I was displaying the dialog from a button click, then the button click handler would be defined in MainWindow.xaml.cpp and I would have access to all the UI objects. But I don't know how to get a reference to the ContentDialog to use in the background thread.
I thought I could get it from the window object after the make function but that object is not of type MainWindow. If I could get the MainWindow object from window and then save it somewhere that would probably work.
My other thought is if there is an event I can define in MainWindow.xaml.cpp that will get called upon window creation, then maybe I can save a reference to the ContentDialog. Or maybe there is some other way to directly expose the ContentDialog control from within MainWindow.xaml.g.h.
Источник: https://stackoverflow.com/questions/781 ... und-thread