如果你有 iOS 应用并想要将其引入Windows,AI 工具可以执行大部分映射工作。 本页提供从 UIKit/SwiftUI 到 WinUI 3 的关键概念翻译。 在提示 AI 代理时,将这些表用作上下文 — 提前提供确切的 API 映射会生成比要求进行泛型转换更准确的输出。
首先安装 WinUI 代理插件 ,以便为代理提供准确的 WinUI 3 知识:
gh copilot plugin install winui@awesome-copilot
概念映射
| iOS (UIKit /SwiftUI) | WinUI 3 对应项 | 备注 |
|---|---|---|
UIViewController |
Page |
WinUI 页面通过 Frame 进行导航 |
UINavigationController |
Frame + NavigationView |
使用 Frame.Navigate() 进行页面切换 |
UITabBarController |
NavigationView (顶部或左侧选项卡) |
|
UITableView |
ListView |
使用 ObservableCollection<T> 进行数据绑定 |
UICollectionView |
GridView |
|
UIAlertController |
ContentDialog |
必须隶属于当前的 XamlRoot |
UILabel |
TextBlock |
|
UITextField |
TextBox |
|
UIButton |
Button |
|
UIImageView |
Image |
|
UIStackView |
StackPanel |
Orientation设置为Horizontal或Vertical |
Auto Layout |
Grid / StackPanel / RelativePanel |
XAML 布局基于行/列 |
@State
/
@Binding (SwiftUI) |
INotifyPropertyChanged
/
ObservableProperty (CommunityToolkit.Mvvm) |
|
NSUserDefaults |
ApplicationData.Current.LocalSettings |
|
URLSession |
HttpClient |
使用 System.Net.Http.HttpClient |
NotificationCenter |
Events 或 WeakReferenceMessenger (CommunityToolkit.Mvvm) |
|
DispatchQueue.main.async |
DispatcherQueue.TryEnqueue |
|
AppDelegate.applicationDidFinishLaunching |
App.OnLaunched |
|
SceneDelegate / windowScene |
MainWindow / AppWindow |
|
FileManager |
StorageFolder / StorageFile |
|
UserNotifications |
AppNotificationManager (Microsoft.Windows.AppNotifications) |
初学者提示
使用此提示为 AI 代理提供开始迁移之前所需的上下文:
I'm migrating an iOS app to WinUI 3 using the Windows App SDK.
The app is written in [Swift / Objective-C] using [UIKit / SwiftUI].
Apply these mappings:
- UIViewController → Page, navigated via Frame
- UINavigationController → Frame + NavigationView
- UITableView → ListView with ObservableCollection<T>
- UIAlertController → ContentDialog (parented to XamlRoot)
- NSUserDefaults → ApplicationData.Current.LocalSettings
- URLSession → System.Net.Http.HttpClient
- DispatchQueue.main.async → DispatcherQueue.TryEnqueue
- @State / @Binding → INotifyPropertyChanged via CommunityToolkit.Mvvm
Use Microsoft.UI.Xaml.* namespaces throughout — never Windows.UI.Xaml.*.
Generate C# — not Swift.
无法直接映射的内容
某些 iOS 概念没有直接的 WinUI 等效项:
-
应用内购买:通过 使用
Windows.Services.Store - 推送通知 (APNs):使用 Windows 推送通知服务(WNS)
- HealthKit / ARKit / CoreML:Windows具有相关技术领域Windows ML, Windows Mixed Reality 和 Windows Sensors ,但这些不是直接等效项,需要特定于平台的实现
- App Clips:无直接对应项 — 请考虑网页到应用的链接