2017-04-01 45 views
0

我想建立與sytacklayout特定的填充幾頁。我不想寫在每一頁。考慮到未來我想改變它,它的設計並不好。有沒有辦法在靜態資源中定義填充?所以,我可以在一個地方App.xml定義,並在其他頁面中使用它。Xamarin表格填充在靜態資源

我已經試過

<ContentPage.Resources> 
    <ResourceDictionary> 
     <x:String x:Key="padding">45, 0, 45, 0</x:String> 
    </ResourceDictionary> 
</ContentPage.Resources> 
<StackLayout Padding="{StaticResource padding}"> 
    <Label Text="{StaticResource padding}"/> 
</StackLayout> 
+0

https://developer.xamarin.com/guides/xamarin-forms/user-interface/styles/application/ – EvZ

+0

是可以使用StaticResource。我已經用風格解決了它。但我需要使用靜態資源。爲一個物業定義樣式對我來說不太合適。請指教。並感謝您的答覆。 – Atiq

回答

1

至於說,你應該使用Thickness。此外,在應用程序級別設置你的資源,把它放在你的App.xaml文件:

<Application ...> 
<Application.Resources> 
     <ResourceDictionary> 
      <Thickness x:Key="padding">45,0, 45, 0</Thickness> 
      // some others resources... 
     </ResourceDictionary> 
    </Application.Resources> 
</Application> 

然後從不同的頁面調用它:

​​

link to documentation

希望它能幫助!

0

只需使用的Thickness代替string

<ContentPage.Resources> 
<ResourceDictionary> 
    <Thickness x:Key="padding">45,0</Thickness> 
</ResourceDictionary> 
</ContentPage.Resources> 
<StackLayout Padding="{StaticResource padding}"> 
    <Label Text="{StaticResource padding}"/> 
</StackLayout>