全局样式在iOS中不起作用

时间:2018-05-27 20:03:36

标签: xamarin.forms xamarin.ios

我在Xamarin论坛上发布了这个,但没有回复。 我在app.xaml中定义了以下全局样式并应用于内容页面(请参阅附件)。这在Android和UWP中按预期工作,但在iOS中不起作用。在Android和UWP中,背景为深灰色,填充为20.在iOS中,背景为白色,没有填充。在iOS中,所有样式都不起作用,但顶部定义的颜色适用于所有平台。

的App.xaml

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Rhyme4RhymeApp.App">
    <Application.Resources>
        <ResourceDictionary>
            <Color x:Key="backgroundColor">#3F3F3F</Color>
            <Color x:Key="navBackgroundColor">#232323</Color>
            <Color x:Key="textColor">#ffffff</Color>
            <Color x:Key="textColorAccent">#191919</Color>
            <Color x:Key="imageBackgroundColor">#191919</Color>


            <Color x:Key="DarkGrey">#191919</Color>
            <Color x:Key="Grey">#3F3F3F</Color>
            <Color x:Key="LightGrey">#6a6a6a</Color>
            <Color x:Key="White">#ffffff</Color>
            <Color x:Key="Orange">#f77e4f</Color>
            <Style x:Key="pageStyle" TargetType="Page" ApplyToDerivedTypes="True">
                <Setter Property="BackgroundColor" Value="#3F3F3F" />
                <Setter Property="Padding" Value="20" />
            </Style>
            <Style x:Key="NavStyle" TargetType="Page">
                <Setter Property="BackgroundColor" Value="#383838" />
                <Setter Property="Padding" Value="20" />
            </Style>
            <Style x:Key="semiTransparentColor" TargetType="Layout">
                <Setter Property="BackgroundColor" Value="#000000" />
                <Setter Property="Opacity" Value=".9"/>
            </Style>
            <Style x:Key="masterDetailMenuStyle" TargetType="Page">
                <Setter Property="BackgroundColor" Value="#3F3F3F" />
            </Style>
            <Style x:Key="buttonStyle" TargetType="Button" ApplyToDerivedTypes="True">
                <Setter Property="HorizontalOptions" Value="Center" />
                <Setter Property="BorderColor" Value="#191919" />
                <Setter Property="BorderRadius" Value="0" />
                <Setter Property="BorderWidth" Value="1" />
                <Setter Property="TextColor" Value="#191919" />
                <Setter Property="BackgroundColor" Value="#ffffff" />
            </Style>
            <Style x:Key="linkStyle" TargetType="Label">
                <Setter Property="TextColor" Value="#f77e4f" />
            </Style>
            <Style x:Key="Header1LabelStyle" TargetType="Label">
                <Setter Property="TextColor" Value="#ffffff" />
                <Setter Property="FontSize" Value="28" />
                <Setter Property="FontAttributes" Value="Bold"/>
            </Style>
            <Style x:Key="Header2LabelStyle" TargetType="Label">
                <Setter Property="TextColor" Value="#ffffff" />
                <Setter Property="FontSize" Value="24" />
            </Style>
            <Style x:Key="Header3LabelStyle" TargetType="Label">
                <Setter Property="TextColor" Value="#ffffff" />
                <Setter Property="FontSize" Value="20" />
                <Setter Property="FontAttributes" Value="Bold"/>
            </Style>
            <Style x:Key="Header4LabelStyle" TargetType="Label">
                <Setter Property="TextColor" Value="#ffffff" />
                <Setter Property="FontSize" Value="20" />
            </Style>

            <Style x:Key="quoteLabelStyle" TargetType="Label">
                <Setter Property="TextColor" Value="#ffffff" />
                <Setter Property="FontSize" Value="28" />
                <Setter Property="FontAttributes" Value="Italic"/>
            </Style>
            <Style x:Key="albumLabelStyle" TargetType="Label">
                <Setter Property="TextColor" Value="#ffffff" />
                <Setter Property="FontSize" Value="23" />
                <Setter Property="FontAttributes" Value="Bold"/>
            </Style>
            <Style x:Key="artistLabelStyle" TargetType="Label">
                <Setter Property="TextColor" Value="#ffffff" />
                <Setter Property="FontSize" Value="18" />
                <Setter Property="FontAttributes" Value="Bold"/>
            </Style>
            <Style x:Key="standardLabelStyle" TargetType="Label">
                <Setter Property="TextColor" Value="#ffffff" />
                <Setter Property="FontSize" Value="14" />
            </Style>
            <Style x:Key="imageBackground" TargetType="Image">
                <Setter Property="BackgroundColor" Value="#afafaf" />
            </Style>
            <Style x:Key="artistListItem" TargetType="TextCell">
                <Setter Property="TextColor" Value="#ffffff"/>
            </Style>

        </ResourceDictionary>
    </Application.Resources>
</Application>

内容页面

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Rhyme4RhymeApp.NewQuotesPage" Style="{DynamicResource pageStyle}">
    <ContentPage.Content>
        <StackLayout x:Name="mainStack">
            <ActivityIndicator x:Name="loader" Color="{DynamicResource White}" IsEnabled="True" IsVisible="True" IsRunning="True" />
            <Label x:Name="lblAddedHeader" FontSize="Large" FontAttributes="Bold" TextColor="{DynamicResource White}" />
            <Label x:Name="lblNoResults" Text="" FontSize="Default" FontAttributes="Bold" TextColor="{DynamicResource White}" IsVisible="False" />
            <ListView x:Name="QuotesListView" AutomationId="WhatsNewLVQuotes" HorizontalOptions="FillAndExpand" CachingStrategy="RecycleElement" BackgroundColor="{DynamicResource Grey}"></ListView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

1 个答案:

答案 0 :(得分:0)

请用此替换您的XAML代码:

 <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Rhyme4RhymeApp.NewQuotesPage" Style="{StaticResource pageStyle}">
    <ContentPage.Content>
        <StackLayout x:Name="mainStack">
            <ActivityIndicator x:Name="loader" Color="{StaticResource textColor}" IsEnabled="True" IsVisible="True" IsRunning="True" />
            <Label x:Name="lblAddedHeader" FontSize="Large" FontAttributes="Bold" TextColor="{StaticResource textColor}" />
            <Label x:Name="lblNoResults" Text="" FontSize="Default" FontAttributes="Bold" TextColor="{StaticResource textColor}" IsVisible="False" />
            <ListView x:Name="QuotesListView" AutomationId="WhatsNewLVQuotes" HorizontalOptions="FillAndExpand" CachingStrategy="RecycleElement" BackgroundColor="{StaticResource backgroundColor}"></ListView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>