Xamarin 中的 macOS 用户界面控件macOS user interface controls in Xamarin.Mac

本文链接到描述各种 macOS UI 控件的指南。This article links to guides that describe various macOS UI controls.

在 Xamarin 应用C# 程序中使用和 .net 时,您可以访问与在Xcode 和中工作的开发人员相同的用户界面控件。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 应用程序中使用 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 内部示例文档的 "向目标的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 中创建和维护窗口和面板,如何从 xib 文件、使用 windows 和使用 windows 响应 windows 中C#加载窗口和面板。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 应用程序中的标准控件,如按钮、标签、文本字段、复选框和分段控件。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 应用程序中使用表视图。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.