在 Xamarin. Mac 中 macOS 使用者介面控制項macOS user interface controls in Xamarin.Mac

本文會連結描述各種 macOS UI 控制項的指南。This article links to guides that describe various macOS UI controls.

在 Xamarin. C# Mac 應用程式中使用和 .net 時,您可以存取開發人員在目標-CXcode中工作的相同使用者介面控制項。When working with C# and .NET in a Xamarin.Mac application, you have access to the same user interface controls that a developer working in Objective-C and Xcode does. 因為 Xamarin 會直接與 Xcode 整合,所以您可以使用 Xcode 的_Interface Builder_來建立和維護使用者介面(或選擇直接在程式碼中C#建立)。Because Xamarin.Mac integrates directly with Xcode, you can use Xcode's Interface Builder to create and maintain your user interfaces (or optionally create them directly in C# code).

下列指南提供有關在 Xamarin. Mac 應用程式中使用 macOS UI 元素的詳細資訊。The guides listed below give detailed information about working with macOS UI elements in a Xamarin.Mac application. 強烈建議您先流覽Hello,Mac文章,特別是Xcode 和 Interface Builder和「輸出」和「動作」區段的簡介,其中涵蓋了我們將在中使用的重要概念和技巧。每篇文章。It is highly suggested that you work through the Hello, Mac article first, specifically the Introduction to Xcode and Interface Builder and Outlets and Actions sections, as it covers key concepts and techniques that we'll be using in every article.

您可能會想要查看Xamarin. Mac 內部檔的將類別/方法公開C#至目標-C一節,因為它會說明用來將C#類別連線到的RegisterExport屬性。目標-C 物件和 UI 元素。You may want to take a look at the Exposing C# classes / methods to Objective-C section of the Xamarin.Mac Internals document as well, as it explains the Register and Export attributes used to wire-up your C# classes to Objective-C objects and UI elements.

WindowsWindows

本文說明如何在 Xamarin. Mac 應用程式中使用 windows 和麵板。This article covers working with windows and panels in a Xamarin.Mac application. 它涵蓋了如何在 Xcode 和 Interface Builder 中建立和維護 windows 和麵板、從分鏡腳本或 xib 檔案載入視窗和麵板、使用 windows,以及在C#程式碼中回應 windows。It covers creating and maintaining windows and panels in Xcode and Interface Builder, loading windows and panels from .storyboard or .xib files, using windows, and responding to windows in C# code.

對話方塊Dialogs

本文涵蓋在 Xamarin. Mac 應用程式中使用對話方塊和強制回應視窗。This article covers working with dialogs and modal windows in a Xamarin.Mac application. 其中涵蓋了如何在 Xcode 和 Interface Builder 中建立和維護模式視窗、使用標準對話方塊,以及在程式碼中C#顯示和回應視窗。It covers creating and maintaining modal windows in Xcode and Interface Builder, working with standard dialogs, and displaying and responding to windows in C# code.

警示Alerts

本文說明如何在 Xamarin. Mac 應用程式中使用警示。This article covers working with alerts in a Xamarin.Mac application. 其中包含從C#程式碼建立和顯示警示,以及回應警示。It covers creating and displaying alerts from C# code and responding to alerts.

功能表用於 Mac 應用程式使用者介面的各個部分;從畫面頂端的應用程式主功能表,到可顯示在視窗任何位置的快顯功能表。Menus are used in various parts of a Mac application's user interface; from the application's main menu at the top of the screen to pop-up menus and contextual menus that can appear anywhere in a window. 功能表是 Mac 應用程式使用者體驗不可或缺的一部分。Menus are an integral part of a Mac application's user experience. 本文說明如何在 Xamarin. Mac 應用程式中使用 Cocoa 功能表。This article covers working with Cocoa menus in a Xamarin.Mac application.

標準控制項Standard controls

使用標準 AppKit 控制項(例如按鈕、標籤、文字欄位、核取方塊,以及 Xamarin. Mac 應用程式中的分段控制項)。Working with the standard AppKit controls such as buttons, labels, text fields, check boxes, and segmented controls in a Xamarin.Mac application. 本指南說明如何將這些專案新增至 Xcode Interface Builder 中的使用者介面設計、透過輸出和動作將其公開至程式碼,以及在C#程式碼中使用 AppKit 控制項。This guide covers adding them to a user interface design in Xcode's Interface Builder, exposing them to code through outlets and actions, and working with AppKit controls in C# code.

工具列Toolbars

本文說明如何在 Xamarin. Mac 應用程式中使用工具列。This article covers working with toolbars in a Xamarin.Mac application. 它涵蓋了如何建立和維護 Xcode 和 Interface Builder 中的工具列,如何使用輸出和動作將工具列專案公開至程式碼、啟用和停用工具列專案,最後回應程式C#代碼中的工具列專案。It covers creating and maintaining toolbars in Xcode and Interface Builder, how to expose the toolbar items to code using outlets and actions, enabling and disabling toolbar items, and finally responding to Toolbar items in C# code.

資料表視圖Table views

本文說明如何在 Xamarin. Mac 應用程式中使用資料表的 views。This article covers working with table views in a Xamarin.Mac application. 其中涵蓋在 Xcode 和 Interface Builder 中建立和維護資料表的視圖、如何使用輸出和動作將資料表視圖專案公開至程式碼、填入資料表視圖,以及回應程式碼中C#的資料表視圖專案。It covers creating and maintaining table views in Xcode and Interface Builder, how to expose the table view items to code using outlets and actions, populating table views, and responding to table view items in C# code.

大綱視圖Outline views

本文說明如何在 Xamarin. Mac 應用程式中使用大綱視圖。This article covers working with outline views in a Xamarin.Mac application. 其中涵蓋在 Xcode 和 Interface Builder 中建立和維護大綱視圖、如何使用輸出和動作將大綱視圖專案公開至程式碼、填入大綱視圖,以及回應程式碼中的C#大綱視圖專案。It covers creating and maintaining outline views in Xcode and Interface Builder, how to expose the outline view items to code using outlets and actions, populating outline views, and responding to outline view items in C# code.

來源清單Source lists

本文說明如何在 Xamarin. Mac 應用程式中使用來源清單。This article covers working with source lists in a Xamarin.Mac application. 它涵蓋了如何建立和維護 Xcode 和 Interface Builder 中的來源清單、如何使用輸出和動作將來源清單專案公開給程式碼、填入來源清單,以及回應程式C#代碼中的來源清單專案。It covers creating and maintaining source lists in Xcode and Interface Builder, how to expose source list items to code using outlets and actions, populating source lists, and responding to source list items in C# code.

集合視圖Collection views

本文說明如何在 Xamarin. Mac 應用程式中使用集合視圖。This article covers working with collection views in a Xamarin.Mac application. 其中涵蓋在 Xcode 和 Interface Builder 中建立和維護集合視圖、如何使用輸出和動作將集合視圖專案公開至程式碼、填入集合視圖,以及回應程式碼中C#的集合視圖。It covers creating and maintaining collection views in Xcode and Interface Builder, how to expose the collection view items to code using outlets and actions, populating collection views, and responding to collection views in C# code.

建立自訂控制項Creating custom controls

本文說明如何建立自訂使用者介面控制項(藉由繼承 NSControl)、繪製控制項的自訂介面,以及建立可與 Xcode 的 Interface Builder 搭配使用的自訂動作。This article covers creating custom user interface controls (by inheriting from NSControl), drawing a custom interface for the control, and creating custom actions that can be used with Xcode's Interface Builder.

我們也建議您看一下Mac 範例庫We also suggest taking a look at the Mac Samples Gallery. 其中包含許多立即可用的程式碼,可協助您快速地將 Xamarin. Mac 專案離線。It includes a wealth of ready-to-use code that can help you get a Xamarin.Mac project off the ground quickly.