ファイルベース実行例4.
File-based Apps で、WinUI 3 デスクトップアプリ を作成する
Section titled “ファイルベース実行例4. File-based Apps で、WinUI 3 デスクトップアプリ を作成する”統合開発環境 Visual Studio が無くとも、極論「 メモ帳 」と「 1つの C# ファイル 」だけで、
WinUI 3 デスクトップアプリ を作って実行する… なんてことも、
File-based Apps で、実際にできてしまいます。(やや茨の道ですが)。
ソースコード
Section titled “ ソースコード”Program.cs (WinUI 3)
Section titled “ Program.cs (WinUI 3)”#!/usr/bin/env dotnet#:property TargetFramework=net10.0-windows10.0.26100.0#:property UseWinUI=true#:property WindowsAppSDKSelfContained=true#:property WindowsPackageType=None#:property RuntimeIdentifier=win-x64#:property Nullable=enable#:package Microsoft.UI.Reactor@0.1.0-*
using Microsoft.UI.Reactor;using Microsoft.UI.Reactor.Core;using static Microsoft.UI.Reactor.Factories;
ReactorApp.Run<App>("WinUI3", width: 320, height: 160);
file class App : Component{ public override Element Render() { var (cnt, setCnt) = UseState(0);
return VStack(12, TextBlock($"カウント: {cnt}") .FontSize(20) .SemiBold(), HStack(8, Button("-1", () => setCnt(--cnt)), Button("リセット", () => setCnt(0)), Button("+1", () => setCnt(++cnt)) ) ) .Padding(24) .Backdrop(BackdropKind.Mica); }}使用ライブラリの、ライセンス表記
Microsoft.UI.Reactor
MIT License
Copyright (c) Microsoft Corporation.
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWAREGitHub - microsoft/microsoft-ui-reactor: Reactor is an experimental set of extensions to WinUI
Reactor is an experimental set of extensions to WinUI - microsoft/microsoft-ui-reactor
https://github.com/microsoft/microsoft-ui-reactor
$> dotnet Program.csコンパイル済みの実行ファイル (EXE) ではなく、
C#ソースコードを記述した、ただのテキストファイル 1つ をコマンドからキックしただけですが、
以下のように WinUI 3 のウィンドウが表示されて、ちゃんと問題なく動作します。
先ほどの File-based Apps で WinForms の例 では C# ソースコード 100行弱 もかかっていましたが、
WinUI 3 では 35 行程度で、サクッと実現できてしまいました。


