Споделяне чрез


Default image directory on Windows

This Universal Windows Platform platform-specific defines the directory in the project that image assets will be loaded from. It's consumed in XAML by setting the Application.ImageDirectory to a string that represents the project directory that contains image assets:

<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>

Alternatively, it can be consumed from C# using the fluent API:

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

The Application.On<Windows> method specifies that this platform-specific will only run on the Universal Windows Platform. The Application.SetImageDirectory method, in the Xamarin.Forms.PlatformConfiguration.WindowsSpecific namespace, is used to specify the project directory that images will be loaded from. In addition, the GetImageDirectory method can be used to return a string that represents the project directory that contains the application image assets.

The result is that all images used in an application will be loaded from the specified project directory.