未使用隐式样式设置内容页面属性

时间:2016-08-26 17:39:38

标签: xaml xamarin.forms prism

使用Prism.Forms 6.2和Xamarin.Forms 2.3.3.118 pre-1,当我在应用程序资源文件中设置内容页面填充时,不会仅对内容页面填充进行全局跟踪。所有其他资源属性正确流动。这是我的app.xaml代码:

<?xml version="1.0" encoding="utf-8"?>
<prism:PrismApplication xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        x:Class="MyNamespace.App"
        xmlns:prism="clr-namespace:Prism.Unity;assembly=Prism.Unity.Forms"
        xmlns:local="clr-namespace:MyNamespace;assembly=MyNamespace">
    <prism:PrismApplication.Resources>
        <!-- Application resource dictionary -->
        <ResourceDictionary>
            <converter:DebuggingConverter x:Key="localDebuggingConverter"/>
            <local:ItemTappedEventArgsToItemTappedConverter x:Key="SelectedItemConverter" />
            <Style TargetType="Label">
                <Setter Property="FontSize" >
                    <Setter.Value>
                        <!--iOS default is 17 and is not the same size as android 14. If FontSize is left at default it will be larger on iOS than android-->
                        <OnPlatform x:TypeArguments="x:Double"
                            iOS="14" 
                            Android="14">
                        </OnPlatform>
                    </Setter.Value>
                </Setter>
                <Setter Property="VerticalOptions" Value="Center">
                </Setter>
            </Style>
            <Style TargetType="ContentPage">
                <Setter Property="Padding">
                    <Setter.Value>
                        <OnPlatform x:TypeArguments="Thickness"
                            iOS="5, 28, 5, 5"
                            Android="5, 8, 5, 5"
                            WinPhone="5, 8, 5, 5" />
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </prism:PrismApplication.Resources>
</prism:PrismApplication>

这是我的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" 
        xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
        xmlns:local="clr-namespace:MyNamespace;assembly=MyNamespace"
        prism:ViewModelLocator.AutowireViewModel="True" 
        x:Class="MyNamespace.Views.ChooseProfileView">
    <!--<ContentPage.Padding>
        If I set the content padding this way it is rendered correctly. When this is commented out as it is now the padding is not set by the application resource (implicit style).
        <OnPlatform x:TypeArguments="Thickness"
                            iOS="5, 28, 5, 5"
                            Android="5, 8, 5, 5"
                            WinPhone="5, 8, 5, 5" />
    </ContentPage.Padding>  -->
    <ContentPage.Content>
<!-- whatever content. The padding set here is displayed correctly-->
    </ContentPage.Content>
</ContentPage>

任何想法有什么不对?

1 个答案:

答案 0 :(得分:0)

样式中的TargetType设置为ContextPage,但实际类型为ChooseProfileView。

Xamarin.Forms.Style.TargetType Property

  

开发人员应该知道隐式样式仅应用于Style.TargetType描述的特定类型,而不应用于从其继承的类型。