麦田

不积跬步无以至千里.

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="WinuiApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WinuiApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Title="WinuiApp">

    <Grid>
        <TextBlock Name="tbTxt" Text="{x:Bind MyProperty}"/>
        <Button Name="btnClick" Content="点我" Click="btnClick_Click"/>
    </Grid>
</Window>
#pragma once

#include "MainWindow.g.h"

namespace winrt::WinuiApp::implementation
{
    struct MainWindow : MainWindowT<MainWindow>
    {
    private:
        int32_t myPropertyValue = 32;
    public :
        MainWindow()
        {
            // Xaml objects should not call InitializeComponent during construction.
            // See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
        }

        int32_t MyProperty();
        void MyProperty(int32_t value);
        void btnClick_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
    };
}

namespace winrt::WinuiApp::factory_implementation
{
    struct MainWindow : MainWindowT<MainWindow, implementation::MainWindow>
    {
    };
}
#include "pch.h"
#include "MainWindow.xaml.h"
#if __has_include("MainWindow.g.cpp")
#include "MainWindow.g.cpp"
#endif

using namespace winrt;
using namespace Microsoft::UI::Xaml;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace winrt::WinuiApp::implementation
{
    int32_t MainWindow::MyProperty()
    {
        return myPropertyValue;
    }

    void MainWindow::MyProperty(int32_t value)
    {
        myPropertyValue = value;
        this->Bindings->Update();
        OutputDebugString(L"属性值更新到:");
        OutputDebugString(winrt::to_hstring(myPropertyValue).c_str());
    }
}

void winrt::WinuiApp::implementation::MainWindow::btnClick_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
    MyProperty(myPropertyValue+1);
}

 

posted on 2025-08-30 20:27  一些记录  阅读(17)  评论(0)    收藏  举报