Advertisement
Dijuna

MainPage.*

Jun 25th, 2019
1,532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //MainPage.idl
  2. namespace NOVAStudent
  3. {
  4.     [default_interface]
  5.     runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
  6.     {
  7.         MainPage();
  8.         Windows.Foundation.IAsyncAction on_myButton_clicked();
  9.     }
  10. }
  11.  
  12. //MainPage.xaml
  13. <Page
  14.     x:Class="NOVAStudent.MainPage"
  15.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  16.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  17.     xmlns:local="using:NOVAStudent"
  18.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  19.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  20.     mc:Ignorable="d">
  21.  
  22.     <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
  23.         <Button x:Name="myButton" Click="on_myButton_clicked">Click Me</Button>
  24.     </StackPanel>
  25. </Page>
  26.  
  27. //MainPage.h
  28. #pragma once
  29. #include "MainPage.g.h"
  30. namespace winrt::NOVAStudent::implementation
  31. {
  32.     struct MainPage : MainPageT<MainPage>
  33.     {
  34.         MainPage();
  35.         IAsyncAction on_myButton_clicked(Windows::Foundation::IInspectable const& /*sender*/, Windows::UI::Xaml::RoutedEventArgs const& /*args*/);
  36.     };
  37. }
  38.  
  39. //ConnectTask.h
  40. #pragma once
  41. #include "pch.h"
  42. using namespace winrt::Windows::Foundation;
  43. namespace Tasks
  44. {
  45.     class ConnectTask
  46.     {
  47.     public:
  48.         static IAsyncOperation<bool> RunAsync()
  49.         {
  50.             co_await resume_background();
  51.  
  52.             return false;
  53.         }
  54.     };
  55. }
  56.  
  57. //MainPage.cpp
  58. #include "pch.h"
  59. #include "MainPage.h"
  60. #include "MainPage.g.cpp"
  61. #include "ConnectTask.h"
  62. using namespace winrt;
  63. using namespace Windows::UI::Xaml;
  64. using namespace Tasks;
  65. namespace winrt::NOVAStudent::implementation
  66. {
  67.     MainPage::MainPage()
  68.     {
  69.         InitializeComponent();
  70.     }
  71.     IAsyncAction MainPage::on_myButton_clicked(IInspectable const&, RoutedEventArgs const&)
  72.     {
  73.         myButton().Content(box_value(co_await ConnectTask::RunAsync() ? L"Not connected" : L"Connected"));
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement