我正在使用資源字典了很多,但它是繁瑣的,不得不將它們從一個Xaml複製並粘貼到另一個Xaml以使它們全部更新。我看到完成的唯一方法是繼承一個樣式類,但我不喜歡在C#中聲明屬性的方式(我更喜歡XAML的更多可視化樹語法)。有沒有辦法讓一個XAML從另一個繼承?或者我可以調用每個Xamarin.Forms.ContentPage創建的從StylePage繼承的LoadXaml()方法?XamarinForms XAML:如何從ResourceDictionaries等其他XAML文件繼承屬性?
這是我的風格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="Demo.StylePage">
<!-- Shared Properties -->
<ContentPage.Resources>
<ResourceDictionary>
<!-- TitleBar Styles -->
<Style x:Key="TitleBarStyle" TargetType="StackLayout">
<Setter Property="BackgroundColor" Value="#5db3d6"/>
<Setter Property="Padding" Value="15,6"/>
<Setter Property="HeightRequest" Value="44"/>
</Style>
<Style x:Key="TitleBarHeaderStyle" TargetType="Label">
<Setter Property="TextColor" Value="White"/>
<Setter Property="VerticalOptions" Value="CenterAndExpand"/>
<!-- <Setter Property="FontSize" Value="18"/>-->
<Setter Property="HorizontalOptions" Value="FillAndExpand"/>
</Style>
<Style x:Key="EmptyFrameStyle" TargetType="Frame">
<Setter Property="HasShadow" Value="false"></Setter>
<Setter Property="BackgroundColor" Value="Transparent"></Setter>
<Setter Property="Padding" Value="0,0"></Setter>
</Style>
</ResourceDictionary>
</ContentPage.Resources>
</ContentPage>
我怎麼可能從另一個文件裝載該資源字典?謝謝你的時間,謝爾蓋。
http://developer.xamarin.com/guides/c ross-platform/xamarin-forms/working-with/styles /#Global_Styles_using_Application_Resources –
我已經檢查過了,它使用C#創建資源字典,正是我不想要的。我正在尋找一種方法來從XAML導入資源字典 –