无法在发布版本中设置特定平台的边距。

huangapple go评论122阅读模式
英文:

Cannot set Platform specific Margin in Release-Build

问题

  1. 在我的.NET MAUI应用程序中,我有以下Grid.Resources
  2. ```xml
  3. <Grid.Resources>
  4. <Style TargetType="Entry">
  5. <Setter Property="VerticalTextAlignment" Value="Center"/>
  6. <Setter Property="HorizontalTextAlignment" Value="Center"/>
  7. <Setter Property="Keyboard" Value="Numeric"/>
  8. <!-- <Setter Property="Margin" Value="{OnPlatform iOS='0, 0, 0, 0', Android='0, -5, 0, -3'}" /> -->
  9. </Style>
  10. </Grid.Resources>

在iOS模拟器和Android上的Debug构建中,没有问题,这段代码可以编译通过。

但在Release构建中,用于在我的iPhone上部署时,我会收到一个编译错误,错误信息是"Margin-Setter没有值"。即使我删除iOS属性的值,因为它默认是如此,我仍然会收到此错误。

我可以做什么?

  1. <details>
  2. <summary>英文:</summary>
  3. In my .NET MAUI App, I have the following Grid.Resources:

<Grid.Resources>
<Style TargetType="Entry">
<Setter Property="VerticalTextAlignment" Value="Center"/>
<Setter Property="HorizontalTextAlignment" Value="Center"/>
<Setter Property="Keyboard" Value="Numeric"/>
<!--<Setter Property="Margin" Value="{OnPlatform iOS='0, 0, 0, 0', Android='0, -5, 0, -3'}" />-->
</Style>
</Grid.Resources>

  1. In **Debug**-Build on an iOS-Simulator and Android it is no problem and this code compiles without errors.
  2. In **Releas-Build** to Deploy on my iPhone, I get a Compile-Error &quot;No Value for Setter&quot; on the Margin-Setter. Even when I delete the iOS-Property value as it is default anyway, I get this error.
  3. What can I do?
  4. </details>
  5. # 答案1
  6. **得分**: 1
  7. 我实际上喜欢在设置器中明确使用 `OnPlatforms` 的方法,甚至在我的项目中的发布模式下尝试过,它似乎总是有效的。
  8. 您可以尝试并查看它是否适用于您。
  9. ```xml
  10. <Style TargetType="Entry">
  11. <Setter Property="VerticalTextAlignment" Value="Center" />
  12. <Setter Property="HorizontalTextAlignment" Value="Center" />
  13. <Setter Property="Keyboard" Value="Numeric" />
  14. <Setter Property="Margin">
  15. <Setter.Value>
  16. <OnPlatform x:TypeArguments="Thickness">
  17. <On Platform="Android" Value="0, 0, 0, 0" />
  18. <On Platform="iOS" Value="0, 20, 0, 0" />
  19. </OnPlatform>
  20. </Setter.Value>
  21. </Setter>
  22. </Style>

希望对您有所帮助。

英文:

I actually like to use an explicit approach to using OnPlatforms in setters and I even tried this on Release mode in my project and it always seems to work.

You can try it out and see if it works for you

  1. &lt;Style TargetType=&quot;Entry&quot;&gt;
  2. &lt;Setter Property=&quot;VerticalTextAlignment&quot; Value=&quot;Center&quot; /&gt;
  3. &lt;Setter Property=&quot;HorizontalTextAlignment&quot; Value=&quot;Center&quot; /&gt;
  4. &lt;Setter Property=&quot;Keyboard&quot; Value=&quot;Numeric&quot; /&gt;
  5. &lt;Setter Property=&quot;Margin&quot;&gt;
  6. &lt;Setter.Value&gt;
  7. &lt;OnPlatform x:TypeArguments=&quot;Thickness&quot;&gt;
  8. &lt;On Platform=&quot;Android&quot; Value=&quot;0, 0, 0, 0&quot; /&gt;
  9. &lt;On Platform=&quot;iOS&quot; Value=&quot;0, 20, 0, 0&quot; /&gt;
  10. &lt;/OnPlatform&gt;
  11. &lt;/Setter.Value&gt;
  12. &lt;/Setter&gt;
  13. &lt;/Style&gt;

huangapple
  • 本文由 发表于 2023年7月24日 00:45:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76749344.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定