Xamarin 应用程序基础知识Xamarin.Mac application fundamentals

常见模式和惯例Common patterns and idioms

在通过C#公开的所有 Apple api 中,某些惯例和模式会重新出现。Throughout the Apple APIs exposed via C#, certain idioms and patterns come up over and over again. 如果你有经验来使用 Xamarin 进行编程,这些都可能很熟悉。If you have experience with programming with Xamarin.iOS, these may look familiar. 文档通常会重复引用这些模式和惯例,因此,对其进行深刻了解将有助于你了解所找到的文档。Documentation will often refer to these patterns and idioms repeatedly, so having a solid understanding of them will help you make sense of the documentation you find.

了解 Mac ApiUnderstanding Mac APIs

对于大部分用 Xamarin 开发的时间,您可以考虑、读取和写入, C#而不会对基础目标-C api 有很多关注。For much of your time developing with Xamarin.Mac, you can think, read, and write in C# without much concern with the underlying Objective-C APIs. 但是,有时你需要从 Apple 中阅读 API 文档,将 Stack Overflow 的答案转换为你的问题的解决方案,或将其与现有示例进行比较。However, sometimes you’ll need to read the API documentation from Apple, translate an answer from Stack Overflow to a solution for your problem, or compare to an existing sample.

控制台应用Console apps

你还可以使用 Xamarin 构建访问本机 macOS Api 的 "无外设" 控制台应用。You can also build "headless" console apps that access native macOS APIs using Xamarin.Mac.

使用 xib 文件Working with .xib files

本文介绍如何使用在 Xcode 的 Interface Builder 中创建的 xib 文件来创建和维护 Xamarin 应用程序的用户界面。This article covers working with .xib files created in Xcode's Interface Builder to create and maintain user interfaces for a Xamarin.Mac application.

。 xib 更少的用户界面设计.storyboard/.xib less user interface design

本文介绍如何直接从C#代码创建 Xamarin 应用程序的用户界面,而无需使用 Xcode 或 xib 文件 Interface Builder 的。This article covers creating a Xamarin.Mac application's user interface directly from C# code without using Xcode's Interface Builder with .storyboard or .xib files.

使用图像Working with images

本文介绍如何在 Xamarin. Mac 应用程序中使用图像和图标。This article covers working with images and icons in a Xamarin.Mac application. 它介绍了如何创建和维护在C#代码和 Xcode 的 Interface Builder 中创建应用程序图标和使用图像所需的映像。It covers creating and maintaining the images needed to create your application's icon and using images in both C# code and Xcode's Interface Builder.

数据绑定和键值编码Data binding and key-value coding

本文介绍如何使用键/值编码和键-值观察,以允许数据绑定到 Xcode 的 Interface Builder 中的 UI 元素。This article covers using key-value coding and key-value observing to allow for data binding to UI elements in Xcode's Interface Builder. 使用此方法可以极大地减少需要为 Xamarin C#应用程序编写的代码量。Using this technique, you greatly reduce the amount of C# code that needs to be written for your Xamarin.Mac application.

使用数据库Working with databases

本文介绍如何使用键/值编码和键-值观察,以允许数据绑定直接访问 SQLite 数据库到 Xcode 的 Interface Builder 中的 UI 元素。This article covers using key-value coding and key-value observing to allow for data binding with direct access to SQLite databases to UI elements in Xcode's Interface Builder. 还介绍了如何使用 SQLite.NET ORM 提供对 SQLite 数据的访问。It also covers using the SQLite.NET ORM to provide access to SQLite data.

使用复制和粘贴Working with copy and paste

本文介绍如何使用粘贴板在 Xamarin 应用程序中提供复制和粘贴。This article covers working with the pasteboard to provide copy and paste in a Xamarin.Mac application. 它演示如何处理可在多个应用之间共享的标准数据类型,以及如何支持在提供应用中使用自定义数据。It shows how to work with standard data types that can be shared between multiple apps and how to support custom data within a give app.

对 Xamarin 应用程序进行沙箱处理Sandboxing a Xamarin.Mac app

本文介绍如何对应用商店上的发布进行沙箱处理。This article covers sandboxing a Xamarin.Mac application for release on the App Store. 其中涵盖了所有要进行沙盒处理的元素:容器目录、权利、用户确定的权限、特权分离和内核强制。It covers all of the elements that go into sandboxing: container directories, entitlements, user-determined permissions, privilege separation, and kernel enforcement.

用 Avaudioplayer 播放声音播放声音Playing sound with AVAudioPlayer

本文介绍如何使用 Avaudioplayer 播放声音的帮助器类控制声音播放。This article shows how to use a helper class to control the playback of sound using an AVAudioPlayer.

报告 bugReporting bugs

有时,在处理项目时,所有这些操作都会停滞,因为无法获取 API 来按我们所需的方式工作,也不能尝试解决错误。Sometimes we all get stuck while working on a project, either on the inability to get an API to work the way we want or in trying to work around a bug. Xamarin 的目标是让你能够成功编写移动和桌面应用程序,并提供了一些资源来提供帮助。Our goal at Xamarin is for you to be successful in writing your mobile and desktop applications, and we’ve provided some resources to help.