Skip to content

Instantly share code, notes, and snippets.

@luojunyuan
Created August 24, 2026 20:03
Show Gist options
  • Select an option

  • Save luojunyuan/33c7de9e97299affb661b278b6c14ad7 to your computer and use it in GitHub Desktop.

Select an option

Save luojunyuan/33c7de9e97299affb661b278b6c14ad7 to your computer and use it in GitHub Desktop.
using Microsoft.UI.Reactor.Wrappers;
namespace CommunityToolkit.WinUI.Controls;
[GenerateReactorWrapper(typeof(SettingsCard))]
partial record SettingsCardFactory;
using Microsoft.UI.Reactor;
using Microsoft.UI.Reactor.Core;
using static CommunityToolkit.WinUI.Controls.SettingsCardFactory;
using static Microsoft.UI.Reactor.Factories;
// 注册外部控件 IXamlMetadataProvider (AOT 下必须)
ReactorApp.RegisterControlAssembly(new CommunityToolkit.WinUI.Controls.SettingsControlsRns.CommunityToolkit_WinUI_Controls_SettingsControls_XamlTypeInfo.XamlMetaDataProvider());
ReactorApp.Run<GettingStartedApp>();
class GettingStartedApp : Component
{
public override Element Render()
{
var (name, setName) = UseState("World");
return VStack(16,
TextBlock($"Hello, {name}!").FontSize(24).Bold(),
TextBox(name, setName, placeholderText: "Enter your name").Width(250).AutomationName(""),
SettingsCard(
header: "Launch on startup",
description: "Start Kumoreactor automatically when you sign in.",
content: ToggleSwitch(isOn: true)
)
).Padding(24);
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0-windows10.0.26100.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<WindowsAppSDKSelfContained>false</WindowsAppSDKSelfContained>
<!-- 引入 bootstrap 框架初始化 -->
<WindowsPackageType>None</WindowsPackageType>
<!-- PublishAot 下拷贝 {AssemblyName}.pri 到发布目录 -->
<EnableMsixTooling>true</EnableMsixTooling>
</PropertyGroup>
<!-- PublishAot 下去除发布目录中多余的 Reactor.pri 及 Reactor 文件夹 -->
<Target Name="RemoveReactorAotPublishArtifacts"
AfterTargets="Publish"
Condition="'$(PublishAot)' == 'true'">
<Delete Files="$(PublishDir)Reactor.pri" />
<RemoveDir Directories="$(PublishDir)Reactor" />
</Target>
<ItemGroup>
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.3.260402-preview2" />
<PackageReference Include="Microsoft.UI.Reactor" Version="0.1.0-preview.13" />
<!-- WASDKSelfContained false 需要 Microsoft.WindowsAppSDK.Runtime -->
<PackageReference Include="Microsoft.WindowsAppSDK.Runtime" Version="2.4.0" />
<!-- 以下为 WASDK.Runtime 包所必须的传递依赖提升 -->
<PackageReference Include="Microsoft.WindowsAppSDK.WinUI" Version="2.3.6" />
<PackageReference Include="Microsoft.WindowsAppSDK.InteractiveExperiences" Version="2.1.6" />
<!-- 去除无需的 WebView2 -->
<PackageReference Include="Microsoft.Web.WebView2" Version="*" ExcludeAssets="All" />
</ItemGroup>
</Project>
SettingsCardFactory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment