【发布时间】:2018-11-20 19:21:43
【问题描述】:
在通过MergedDictionaries 合并的ResourceDictionary 中使用Style 时,我不断收到运行时错误StaticResource not found for key。
App.xaml
<Application x:Class="MyApp.App"
xmlns:local="MyApp"
xmlns:assets="clr-namespace:MyApp.Assets">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<assets:Styles />
</ResourceDictionary.MergedDictionaries>
<Style ...>
<!-- other styles... -->
样式.xaml
<ResourceDictionary x:Class="MyApp.Assets.Styles">
<Style x:Key="Subheading" TargetType="Frame">
<Setter Property="BackgroundColor" Value="DarkSlateGray"></Setter>
<Setter Property="HasShadow" Value="True"></Setter>
</Style>
</ResourceDictionary>
Styles.xaml.cs
namespace MyApp.Assets
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Styles : ResourceDictionary
{
public Styles () { }
}
}
Page.xaml
<Frame Style="{StaticResource Subheading}">
应用程序编译正确——只是在运行时找不到Subheading。如果我将 <Style> 节点直接复制到 App.xaml 中,它可以正常工作。谁能找到我不正确的语法?或者,有没有办法在运行时查看 Application.Resources 以便找出它在哪里?
【问题讨论】:
标签: c# xaml xamarin.forms