C# 从代码隐藏中的(子)文件夹获取特定的XAML资源文件
我试图在代码隐藏中使用C# 从代码隐藏中的(子)文件夹获取特定的XAML资源文件,c#,xaml,xamarin,xamarin.forms,C#,Xaml,Xamarin,Xamarin.forms,我试图在代码隐藏中使用样式,该样式设置在特定的资源文件中,这应该是一件相对容易完成的事情,但遗憾的是,我已经花了2个多小时来实现它 我在Xamarin.Forms ContentPage中有以下XAML代码: <?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="PCS2.APP.HomePage" xmlns="http:
样式,该样式设置在特定的资源文件中,这应该是一件相对容易完成的事情,但遗憾的是,我已经花了2个多小时来实现它
我在Xamarin.Forms ContentPage中有以下XAML代码:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="PCS2.APP.HomePage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
xmlns:fftransformations="clr-namespace:FFImageLoading.Transformations;assembly=FFImageLoading.Transformations"
xmlns:grial="clr-namespace:UXDivers.Grial;assembly=UXDivers.Grial"
xmlns:local="clr-namespace:PCS2.APP"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Shell.NavBarIsVisible="False">
<ContentPage.Resources>
<ResourceDictionary Source="/Styles/TabControl/IOSTabResources.xaml" />
</ContentPage.Resources>
<ContentPage.Content>
<grial:TabControl
x:Name="tabControl"
Style="{StaticResource iOSTabStyle}"
TabContentBackgroundColor="{DynamicResource BasePageColor}"
TabStripBackgroundColor="{DynamicResource ArticleHeaderBackgroundColor}">
</grial:TabControl>
</ContentPage.Content>
</ContentPage>
但是,当设置静态资源样式style=(style)Application.Current.Resources[“iOSTabStyle”]
时,我得到错误“找不到资源…”
通常Application.Current.Resources
工作正常,但我注意到在原始XAML文件中,特定的资源文件(其中包含键/styleiOSTabStyle
)是单独加载的:
<ContentPage.Resources>
<ResourceDictionary Source="/Styles/TabControl/IOSTabResources.xaml" />
</ContentPage.Resources>
但是没有任何成功。您能将IOSTabResources
字典插入到应用程序字典中吗?我以前没试过,但应该能用
<ContentPage.Resources>
<ResourceDictionary Source="/Styles/TabControl/IOSTabResources.xaml" />
</ContentPage.Resources>
var myResource = Resources.LoadFromXaml("/Styles/TabControl/IOSTabResources.xaml");