如何在MAUI中使用OnPlatform结构?

问题描述 投票:0回答:2
xamarin maui
2个回答
0
投票

您可以通过这种方式使用 OnPlatform 来根据平台显示/隐藏某些内容:

<StackLayout IsVisible="{OnPlatform iOS=true, Android=false}">
    <Button Text="Annulla" FontSize="Small" TextColor="White" FontAttributes="Bold" BackgroundColor="Transparent" HorizontalOptions="Start" Command="{prism:GoBack UseModalNavigation=True}"/>
    <Label Text="Comunicazione" TextColor="White" FontAttributes="Bold" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
    <Button Text="Salva" TextColor="White" FontAttributes="Bold" BackgroundColor="Transparent" HorizontalOptions="End" Command="{Binding SalvaComunicazioneCommand}"/>
    <Button Text="Rimuovi" TextColor="White" FontAttributes="Bold" BackgroundColor="Transparent" HorizontalOptions="End" Command="{Binding RimuoviComunicazioneCommand}"/>
</StackLayout>

0
投票

我认为即使在 Xamarin 生命周期中,这种语法也已经过时了。这应该是替代品:

<OnPlatform x:TypeArguments="View">
    <On Platform="iOS">
        <StackLayout BackgroundColor="{DynamicResource StandardColor}" Padding="15,5,15,3" Orientation="Horizontal" IsVisible="{Binding Modal}">
            <Button Text="Annulla" FontSize="Small" TextColor="White" FontAttributes="Bold" BackgroundColor="Transparent" HorizontalOptions="Start" Command="{prism:GoBack UseModalNavigation=True}"/>
            <Label Text="Comunicazione" TextColor="White" FontAttributes="Bold" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
            <Button Text="Salva" TextColor="White" FontAttributes="Bold" BackgroundColor="Transparent" HorizontalOptions="End" Command="{Binding SalvaComunicazioneCommand}"/>
            <Button Text="Rimuovi" TextColor="White" FontAttributes="Bold" BackgroundColor="Transparent" HorizontalOptions="End" Command="{Binding RimuoviComunicazioneCommand}"/>
        </StackLayout>
    </On>
    <On Platform="Android">
    </On>
</OnPlatform>

Microsoft Learn 上了解更多相关信息。

请注意,您可能还想研究专门的

HorizontalStackLayout
VerticalStackLayout

© www.soinside.com 2019 - 2024. All rights reserved.