OnPlatformExtension 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供一个 XAML 标记扩展,该扩展根据应用正在运行的平台返回不同的值。
public ref class OnPlatformExtension : Microsoft::Maui::Controls::Xaml::IMarkupExtension
[Microsoft.Maui.Controls.ContentProperty("Default")]
[Microsoft.Maui.Controls.Xaml.RequireService(new System.Type[] { typeof(Microsoft.Maui.Controls.Xaml.IProvideValueTarget), typeof(Microsoft.Maui.Controls.Xaml.IValueConverterProvider), typeof(Microsoft.Maui.Controls.Xaml.IXmlLineInfoProvider), typeof(Microsoft.Maui.Controls.Xaml.IConverterOptions) })]
public class OnPlatformExtension : Microsoft.Maui.Controls.Xaml.IMarkupExtension
[Microsoft.Maui.Controls.ContentProperty("Default")]
public class OnPlatformExtension : Microsoft.Maui.Controls.Xaml.IMarkupExtension
[<Microsoft.Maui.Controls.ContentProperty("Default")>]
[<Microsoft.Maui.Controls.Xaml.RequireService(new System.Type[] { typeof(Microsoft.Maui.Controls.Xaml.IProvideValueTarget), typeof(Microsoft.Maui.Controls.Xaml.IValueConverterProvider), typeof(Microsoft.Maui.Controls.Xaml.IXmlLineInfoProvider), typeof(Microsoft.Maui.Controls.Xaml.IConverterOptions) })>]
type OnPlatformExtension = class
interface IMarkupExtension
[<Microsoft.Maui.Controls.ContentProperty("Default")>]
type OnPlatformExtension = class
interface IMarkupExtension
Public Class OnPlatformExtension
Implements IMarkupExtension
- 继承
-
OnPlatformExtension
- 特性
- 实现
注解
通过将标识符(DevicePlatform结构ToString()的值)与每个平台值匹配Platform来解析该值,因此,平台字符串与以下命名属性之一(例如GTK)匹配的自定义后端在运行时正确解析。 匹配区分 大小 写(序号,按 DevicePlatform 相等),因此标识符必须与属性名称的大小写完全匹配 - 后端报告 DevicePlatform.Create("gtk") (小写)与属性不匹配 GTK ,并且跌至 Default。 请注意,编译时优化(SimplifyOnPlatformVisitor)当前仅/-macos-maccatalyst-ios//-android识别目标框架;所有其他目标框架(包括-windows和-tizen)以及任何自定义后端都回退到运行时解析。
由于 XAML 标记扩展将每个命名参数映射到 CLR 属性,因此内联 {OnPlatform iOS=…, Android=…} 窗体只能将公开的平台表示为此处的属性。 若要以 任意 自定义平台(例如后端报告 DevicePlatform.Create("Web"))为目标,请使用接受任何平台字符串的元素形式:
<OnPlatform x:TypeArguments="x:String">
<On Platform="Web" Value="…" />
<On Platform="iOS, Android" Value="…" />
</OnPlatform>
构造函数
| 名称 | 说明 |
|---|---|
| OnPlatformExtension() |
提供一个 XAML 标记扩展,该扩展根据应用正在运行的平台返回不同的值。 |
属性
| 名称 | 说明 |
|---|---|
| Android |
获取或设置要在 Android 上使用的值。 |
| Converter |
获取或设置要应用于特定于平台的值的转换器。 |
| ConverterParameter |
获取或设置要传递给转换器的参数。 |
| Default |
获取或设置未设置特定于平台的值时要使用的默认值。 |
| GTK |
获取或设置要在 GTK 上使用的值。 |
| iOS |
获取或设置要在 iOS 上使用的值。 |
| MacCatalyst |
获取或设置要在 Mac Catalyst 上使用的值。 |
| macOS |
获取或设置要在 macOS 上使用的值。 |
| Tizen |
获取或设置要在 Tizen 上使用的值。 |
| UWP |
已过时.
获取或设置要在 UWP 上使用的值。 请改用 WinUI。 |
| WinUI |
获取或设置要在 Windows 上使用的值(WinUI)。 |
| WPF |
获取或设置要在WPF上使用的值。 |
方法
| 名称 | 说明 |
|---|---|
| ProvideValue(IServiceProvider) |
提供一个 XAML 标记扩展,该扩展根据应用正在运行的平台返回不同的值。 |