【问题标题】:BoxView not visible in iOSBoxView 在 iOS 中不可见
【发布时间】:2021-03-19 08:57:58
【问题描述】:

我在 App.xaml 中创建了以下 BoxView(作为分隔符)...

<Style x:Key="BoxViewGray" TargetType="BoxView">
      <Setter Property="HeightRequest" Value="0.2"/>
      <Setter Property="Color" Value="Gray"/>
</Style>

...并在我的页面中使用它:

<BoxView Style="{StaticResource BoxViewGray}" />

直截了当,它在 Android(发布和调试)上运行良好,但当我调试 iOS 解决方案时,它是不可见的。也许作为附加信息:我没有用于调试的物理 Mac,但使用 Macincloud 代替。也没有物理设备(iPhone 等)。

更新:页面的完整 XAML 代码:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:vm="clr-namespace:ErzengelMichael.ViewModels"
             x:Class="ErzengelMichael.Views.EinstellungenPage"
             Title="{Binding Rosenkranz[0].TabBarTitleSettings}" >

    <ContentPage.BindingContext>
        <vm:RosenkranzViewModel />
    </ContentPage.BindingContext>

    <ContentPage.Background>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
            <GradientStop Offset="0.1" Color="Purple" />
            <GradientStop Offset="0.9" Color="DarkSlateBlue" />
        </LinearGradientBrush>
    </ContentPage.Background>


    <ScrollView>
        <StackLayout Padding="10" >
            <StackLayout Padding="5">
                <BoxView Style="{StaticResource BoxViewGray}" />
                <Label Text="{Binding Rosenkranz[0].SettingsText}" 
                        HorizontalOptions="Center" FontSize="24" TextColor="White"
                        BackgroundColor="Transparent" Margin="0,0,0,5" />
                
                <BoxView Style="{StaticResource BoxViewGray}" />
            </StackLayout>

            <StackLayout Orientation="Vertical" Padding="10"  >
                <StackLayout HorizontalOptions="Center" Orientation="Horizontal" Spacing="20" Padding="10">
                    <ImageButton CornerRadius="10" HeightRequest="80" BackgroundColor="Transparent" CommandParameter="French" 
                                Command="{Binding ChangeLanguageCommand}" Source="france.jpg" VerticalOptions="Center"  />
                    <ImageButton CornerRadius="10" HeightRequest="80" BackgroundColor="Transparent" CommandParameter="German" 
                                Command="{Binding ChangeLanguageCommand}" Source="germany.jpg" VerticalOptions="Center" />
                </StackLayout>

                <StackLayout HorizontalOptions="Center" Orientation="Horizontal" Spacing="20" Padding="10" >
                    <ImageButton CornerRadius="10" HeightRequest="80" BackgroundColor="Transparent" 
                                CommandParameter="English" Command="{Binding ChangeLanguageCommand}" Source="usa.jpg" VerticalOptions="Center" />
                    <ImageButton CornerRadius="10" HeightRequest="80" BackgroundColor="Transparent" CommandParameter="Spanish" 
                                Command="{Binding ChangeLanguageCommand}" Source="spain.jpg" VerticalOptions="Center" />
                </StackLayout>

                <StackLayout HorizontalOptions="Center" Orientation="Horizontal" Spacing="20" Padding="10" >
                    <ImageButton CornerRadius="10" HeightRequest="80" BackgroundColor="Transparent" CommandParameter="Italian" 
                                Command="{Binding ChangeLanguageCommand}" Source="italy.jpg" VerticalOptions="Center" />
                    <ImageButton CornerRadius="10" HeightRequest="80" BackgroundColor="Transparent" CommandParameter="Portugese" 
                                Command="{Binding ChangeLanguageCommand}" Source="portugal.jpg" VerticalOptions="Center" />
                </StackLayout>
            </StackLayout>            

            <!--#region IMPRESSUM -->
            <StackLayout Spacing="15" Padding="10" HorizontalOptions="Center" VerticalOptions="Center">
                <BoxView Style="{StaticResource BoxViewGray}"/>
                <Label HorizontalOptions="Center" HorizontalTextAlignment="Center" Text="Development and Design by xxx@web.de" TextColor="White" />
                <Label HorizontalOptions="Center" Text="Version 1.0" TextColor="White" FontAttributes="Italic"/>
                <Label HorizontalOptions="Center" TextColor="White" HorizontalTextAlignment="Center"
                        Text="Images used in this App are in the public domain worldwide."/>

                <StackLayout Orientation="Horizontal" Spacing="0" HorizontalOptions="Center" >
                    <Label HorizontalTextAlignment="Center" >
                        <Label.FormattedText>
                            <FormattedString>
                                <Span Text="&#xf4ec;" FontFamily="FA-B" TextColor="White" CharacterSpacing="20" FontSize="24" />
                                <Span Text="&#xf4ed;" FontFamily="FA-B" TextColor="White" FontSize="24"  />
                            </FormattedString>
                        </Label.FormattedText>
                    </Label>
                </StackLayout>

                <BoxView Style="{StaticResource BoxViewGray}" />

            </StackLayout>
            <!--#endregion-->

        </StackLayout>
    </ScrollView>
</ContentPage>



【问题讨论】:

  • 页面的根布局是什么?您可以发布 xaml 的完整代码。
  • 嗨 Lucas,我​​已将完整的 xaml 代码添加到原始帖子中!

标签: ios xaml xamarin.forms


【解决方案1】:

那是因为您将 HeightRequest 设置为 0.2(小于 0.5) 。所以在 iOS 中,由于屏幕分辨率,它会在某些设备上被忽略。

所以你最好在 iOS 设备上设置为 0.5 或更高。

  <Style x:Key="BoxViewGray" TargetType="BoxView">
        <Setter Property="HeightRequest">

            <Setter.Value>
                <OnPlatform iOS="0.5" Android="0.2" />
            </Setter.Value>

        </Setter>
        <Setter Property="Color" Value="Gray"/>
    </Style>

【讨论】:

  • 太棒了。谢谢你卢卡斯!
猜你喜欢
  • 2021-10-01
  • 2021-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多