以 Activity.xaml 為例,示範如何在執行時切換外觀樣板:
obj\Debug\Designer\Activity.g.cs 複製欄位宣告與 InitializeComponent 方法至 Activity.xaml.cs。Activity.g.cs 內容並重新編譯。[System.Diagnostics.DebuggerNonUserCodeAttribute()] 屬性,使 InitializeComponent 可設中斷點。Activity.xaml 為 Activity2.xaml,清空對應的 Activity2.g.cs,並修改樣式(如顏色、形狀)。Activity.xaml.cs 中將 LoadComponent 的 URI 參數從 /Activity.xaml 改為 /Activity2.xaml。// 原始
System.Windows.Application.LoadComponent(this, new System.Uri("/ShareDesigner;component/Designer/Activity.xaml", System.UriKind.Relative));
// 修改為
System.Windows.Application.LoadComponent(this, new System.Uri("/ShareDesigner;component/Designer/Activity2.xaml", System.UriKind.Relative));
.xaml.cs 移出,樣板檔(.xaml)獨立管理於資料夾。.g.cs 能否抑制?目前編譯時必然產生於 obj\Debug 目錄。