Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MainPage.idl
- namespace NOVAStudent
- {
- [default_interface]
- runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
- {
- MainPage();
- Windows.Foundation.IAsyncAction on_myButton_clicked();
- }
- }
- //MainPage.xaml
- <Page
- x:Class="NOVAStudent.MainPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="using:NOVAStudent"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d">
- <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
- <Button x:Name="myButton" Click="on_myButton_clicked">Click Me</Button>
- </StackPanel>
- </Page>
- //MainPage.h
- #pragma once
- #include "MainPage.g.h"
- namespace winrt::NOVAStudent::implementation
- {
- struct MainPage : MainPageT<MainPage>
- {
- MainPage();
- IAsyncAction on_myButton_clicked(Windows::Foundation::IInspectable const& /*sender*/, Windows::UI::Xaml::RoutedEventArgs const& /*args*/);
- };
- }
- //ConnectTask.h
- #pragma once
- #include "pch.h"
- using namespace winrt::Windows::Foundation;
- namespace Tasks
- {
- class ConnectTask
- {
- public:
- static IAsyncOperation<bool> RunAsync()
- {
- co_await resume_background();
- return false;
- }
- };
- }
- //MainPage.cpp
- #include "pch.h"
- #include "MainPage.h"
- #include "MainPage.g.cpp"
- #include "ConnectTask.h"
- using namespace winrt;
- using namespace Windows::UI::Xaml;
- using namespace Tasks;
- namespace winrt::NOVAStudent::implementation
- {
- MainPage::MainPage()
- {
- InitializeComponent();
- }
- IAsyncAction MainPage::on_myButton_clicked(IInspectable const&, RoutedEventArgs const&)
- {
- myButton().Content(box_value(co_await ConnectTask::RunAsync() ? L"Not connected" : L"Connected"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement