You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XAML(.NET MAUI)中Windows和Mac对应的OnPlatform平台字符串是什么?

.NET MAUI 平台特定样式的Platform字符串问题

我开发了一个.NET MAUI应用,希望根据运行平台为应用设置样式。在资源字典中使用了如下代码:

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <OnPlatform x:Key="ButtonSize" x:TypeArguments="x:Double">
        <On Platform="iOS" Value="14" />
        <On Platform="Android" Value="16" />
    </OnPlatform>
</ResourceDictionary>

请问Windows和Mac对应的「Platform Strings」应填写什么内容?对应代码示例如下:

<On Platform="???" Value="16" />

回答

对于.NET MAUI的OnPlatform标记扩展,Windows和Mac对应的平台字符串分别是:

  • Windows:Windows
  • Mac(基于Mac Catalyst):MacCatalyst

补充后的完整资源字典代码如下:

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <OnPlatform x:Key="ButtonSize" x:TypeArguments="x:Double">
        <On Platform="iOS" Value="14" />
        <On Platform="Android" Value="16" />
        <On Platform="Windows" Value="16" />
        <On Platform="MacCatalyst" Value="16" />
    </OnPlatform>
</ResourceDictionary>

说明:MAUI的Mac版本基于Mac Catalyst框架构建,因此平台标识需使用MacCatalyst而非直接写Mac。

内容的提问来源于stack exchange,提问作者Bongo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 15:10:22