Windows 上的默认图像目录

此特定于通用 Windows 平台的功能会定义将从中加载图像资产的项目中的目录。 在 XAML 中使用它的方法是通过将 Application.ImageDirectory 设置为 string,以表示包含图像资产的项目目录:

<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:windows="clr-namespace:Xamarin.Forms.PlatformConfiguration.WindowsSpecific;assembly=Xamarin.Forms.Core"
             ...
             windows:Application.ImageDirectory="Assets">
	...
</Application>

或者,可以使用 Fluent API 从 C# 使用它:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.WindowsSpecific;
...
Application.Current.On<Windows>().SetImageDirectory("Assets");

Application.On<Windows> 方法指定此项平台特定功能仅在通用 Windows 平台上运行。 命名空间 Xamarin.Forms.PlatformConfiguration.WindowsSpecific 中的 Application.SetImageDirectory 方法用于指定要从中加载图像的项目目录。 此外,GetImageDirectory 方法还可用于返回表示包含应用程序映像资产的项目目录的 string

结果是应用程序中使用的所有图像都将从指定的项目目录中加载。