共用方式為


參考 WPF 和 WinForms 的應用程式必須釐清 MenuItem 和 ContextMenu 類型

同時參考 Windows Presentation Foundation(WPF)和 Windows Forms(WinForms)的應用程式現在必須釐清特定類型,例如MenuItemContextMenu,以避免編譯階段錯誤。

引進的版本

.NET 10

先前的行為

先前,ContextMenuDataGridDataGridCellMenuMenuItemToolBarStatusBar 類型會解析為 System.Windows.Controls 命名空間,因為它們不存在於 .NET Core 3.1 到 .NET 9.0 的 System.Windows.Forms 命名空間中。

<ImplicitUsings>enable</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>

新行為

System.Windows.FormsSystem.Windows.Controls之間有模棱兩可的參考時,System.Windows.Forms 命名空間中受影響的型別會造成編譯時期錯誤。

CS0104 'ContextMenu' is an ambiguous reference between 'System.Windows.Controls.ContextMenu' and 'System.Windows.Forms.ContextMenu'

中斷性變更的類型

這是來源不相容的 變更。

變更的原因

當無法更新第三方程式庫時,此變更有助於從 .NET Framework 遷移。 .NET 10 應用程式可以繼續參考 .NET Framework 相依性,並在運行時間處理錯誤。

使用別名來解決衝突的命名空間。 例如:

using ContextMenu = System.Windows.Controls.ContextMenu;

如需詳細資訊,請參閱 別名名稱衝突檔

受影響的 API