【问题标题】:Content page property not set with implicit style内容页面属性未使用隐式样式设置
【发布时间】:2017-01-03 10:59:19
【问题描述】:

当我在应用程序资源文件中设置内容页面填充时,使用 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>

有什么想法吗?

【问题讨论】:

    标签: xaml xamarin.forms prism


    【解决方案1】:

    样式中的TargetType设置为ContextPage,但真正的类型是ChooseProfileView。

    Xamarin.Forms.Style.TargetType Property

    开发人员应注意,隐式样式仅适用于 Style.TargetType 描述的特定类型,而不适用于继承自它的类型。

    【讨论】:

    • 我希望在应用的所有内容页面中都有内容填充,而不仅仅是 ChooseProfileView。
    • 那么我误解了这些文档here 吗? ContentPage 是本机 Xamarin.Forms 元素。我不确定ContextPage 的来源。我还想提一下,在我在这个应用程序中实现 Prism 之前,这种样式可以正常工作。
    猜你喜欢
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 2010-11-07
    相关资源
    最近更新 更多