2016-08-26 4 views
0

Prism.Forms 6.2とXamarin.Forms 2.3.3.118より前のバージョンを使用すると、アプリケーションのリソースファイルでコンテンツページのパディングを設定すると、コンテンツページのパディングだけがグローバルに行われません。その他のリソースプロパティはすべて正しく流れています。ここに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> 

任意のアイデアは間違っているでしょうか?

答えて

0

スタイルのTargetTypeはContextPageに設定されていますが、実際のタイプはChooseProfileViewです。

Xamarin.Forms.Style.TargetType Property

開発者は暗黙スタイルだけではなく、そこから継承タイプにStyle.TargetTypeによって記述される特定のタイプに適用されることに注意すべきです。

+0

ChooseProfileViewだけでなく、アプリケーションのすべてのコンテンツページにコンテンツの埋め込みが必要です。 –

+0

XAMLはこれを明示的にサポートしていません。 http://stackoverflow.com/questions/6780605/how-to-make-a-wpf-style-inheritable-to-derived-classesおよびhttp://stackoverflow.com/questions/1592844/applying-a-styleを参照してください。 -to-all-derived-classes-in-wpf – dvorn

+0

私はこれらのドキュメント[ここ](https://developer.xamarin.com/guides/xamarin-forms/user-interface/styles/application/)を誤解していますか? 'ContentPage'はネイティブのXamarin.Forms要素です。 'ContextPage'がどこに来るのか分かりません。また、このアプリでPrismを実装する前に、このスタイリングが正しく機能していることについても言及したかったのです。 –

関連する問題