question

VrindhaJayan-3048 avatar image
0 Votes"
VrindhaJayan-3048 asked ·

How to wait for a co_routine from MFC UI thread(Button click) , which displays UWP content dialog over a WinUI hosted MFC

 void CSampleDlg::OnBnClickedAdd()    
 {    
       …………...……………………...……………...…...………….. 
       …………...……...…...………...…………...…...…...…………. 
       IAsyncAction async = ShowContentDialog();    
       async.Completed([&](IAsyncAction asynctest, AsyncStatus st)    
       {    
               asynctest.GetResults();    
               AfxMessageBox(L"completed ..........");    
       });    
      AfxMessageBox(L"OK before get");    
      async.get();    
      *AfxMessageBox(L"After get");    
      CString csSNum;    
      GetDlgItemText(IDC_EDIT4, csSNum);    
      double sum = _wtof(csSNum);    
      m_customUctrl.SetSum(100.00);*    
 }    
     
 Windows::Foundation::IAsyncAction CSampleDlg::ShowContentDialog()    
 {    
      ContentDialog dialog;    
      dialog.Content(box_value(L"Do you want to continue to update textbox?"));    
      dialog.Title(box_value(L"Confirmation"));    
      dialog.PrimaryButtonText(L"Ok");    
      dialog.SecondaryButtonText(L"Cancel");    
      dialog.CloseButtonText(L"Ok");    
      dialog.XamlRoot(m_customUctrl.XamlRoot());    
      winrt::Windows::UI::Xaml::Controls::ContentDialogResult result = co_await dialog.ShowAsync();    
      if (result == ContentDialogResult::Primary)    
      {    
                AfxMessageBox(L"Primary");    
      }    
     else if (result == ContentDialogResult::Secondary)    
     {    
               AfxMessageBox(L"Secondary");    
     }    
    else    
    {    
               AfxMessageBox(L"Third");    
     }    
     co_return;    
 }    
 In the above code sample, trying to display a UWP content dialog from MFC SDI application(XAML island hosted application). And to set text on a text box based on the ContentDialog button click(Primary or secondary button). Issue is  the code portion after the line "*async.get();* "not executed .    



c++windows-uwp-xaml
· 3
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Will be vey useful to format your code as "Code Sample". How ? Just mark your code and hit Ctrl + K.

0 Votes 0 ·

@flaviu Please check the code

0 Votes 0 ·

@VrindhaJayan-3048

According to the issue, it is more related to XAML Islands. I suggest you could post the issue to Github for better help.


0 Votes 0 ·

0 Answers