平台特定的高度请求

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

Platform specific HeightRequest

问题

iOS模拟器和**Pixel 5 - API 33 (Android 13.0 API 33)**上测试了我的.NET MAUI应用程序。似乎Android在控件所需空间方面显示略有不同。

在一个框架下面我有一个按钮,似乎按钮下面的空间和框架相比太小了,不符合我想要的样子,也不像其他带有按钮的框架那样。在iOS上看起来很好。

因此,当增加框架的HeightRequest时,它在iOS上看起来就不那么好了,但在Android上看起来不错。

我无法为HeightRequest设置特定于平台的设置,因为编译器告诉我不支持HeightRequest。

在XAML中应该如何做,或者只有在Code-Behind中设置它的方法吗?或者在在平台之间切换时,是否有更好的解决此问题的方法?

英文:

I tested my .NET MAUI App on iOS - Emulator and Pixel 5 - API 33 (Android 13.0 API 33). It seems like Android is displaying a little differently regarding how much space controls need.

Below a Frame I have a Button and it is like the space below the Button and the Frame is too small regarding what I want and how the look and feel in other Frames with Buttons is. On iOS it is looking good.

So, when increasing the HeightRequest for the Frame it doesn't look as good as before on iOS but looks good then on Android.

I could not set a platform specific HeightRequest as the compiler told it is not supported for HeightRequest.

How should I do it in XAML or is there only a way to set it in the Code-Behind then? Or are there even better ways to deal with this issue in general when switching between platforms?

答案1

得分: 0

你可以在XAML中完成,例如:

<Frame>
   <Frame.HeightRequest>
      <OnPlatform x:TypeArguments="x:Double">
          <On Platform="Android" Value="50"/>
          <On Platform="iOS" Value="200"/>
      </OnPlatform>
   </Frame.HeightRequest>
</Frame>
英文:

You can do it in the xaml, such as:

&lt;Frame&gt;
   &lt;Frame.HeightRequest&gt;
      &lt;OnPlatform x:TypeArguments=&quot;x:Double&quot;&gt;
          &lt;On Platform=&quot;Android&quot; Value=&quot;50&quot;/&gt;
          &lt;On Platform=&quot;iOS&quot; Value=&quot;200&quot;/&gt;
      &lt;/OnPlatform&gt;
   &lt;/Frame.HeightRequest&gt;
&lt;/Frame&gt;

</details>



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

发表评论

匿名网友

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

确定