我在App.xaml资源字典中定义了一种颜色。当我尝试在ContentView中引用它时,出现运行时异常:
找不到NavbarBackground键的StaticResource
我需要在App.xaml中合并资源字典吗?
应用程式<Application.Resources>
<ResourceDictionary>
<!--Global Styles-->
...
<Color x:Key="NavbarBackground">Black</Color>
...
</ResourceDictionary>
</Application.Resources>
CustomTitleView.xaml
<ContentView>
...
<ContentView.Content>
...
<ImageButton Source="search.png" HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" BackgroundColor="{StaticResource NavbarBackground}" />
...
</ContentView.Content>
</ContentView>
答案 0 :(得分:-1)
如果使用单独的xaml文件定义资源,请使用ResourceDictionary。如果您是App.xaml中的设置值,请在Application.Resources中设置它们。请参阅文档here