將 iOS 應用程式遷移到 WinUI 3

如果你有 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 活動或 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
  • 推播通知(APN):使用Windows推播通知服務(WNS)
  • HealthKit / ARKit / CoreML:Windows 有相關技術領域——Windows ML、Windows Mixed Reality 以及 Windows 感測器但這些並非直接對應,且需平台專屬實作
  • 應用程式剪輯:沒有直接對應的——可以考慮 網頁到應用程式連結