我不断收到此错误:
Xamarin.Forms.Xaml.XamlParseException: Position 10:18. StaticResource not found for key TwoButtonTopBarTemplate.
我正在尝试使用在此页面上创建的模板,并且以相同的方式在其他页面上使用。
<?xml version="1.0" encoding="utf-8" ?>
<likeit:InformationPage
xmlns:likeit="clr-namespace:LikeIT"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:devsdna="clr-namespace:DevsDNA;assembly=DevsDNA.GradientBoxView"
x:Class="LikeIT.News">
<ContentView x:Name="newsContentView"
ControlTemplate="{StaticResource TwoButtonTopBarTemplate}" HeightRequest="100">
<StackLayout Spacing="3">
...
</StackLayout>
</ContentView>
</likeit:InformationPage>
我当然在.cs文件中使用它。
public partial class News : InformationPage
我的TwoButtonTopBarTemplate是在App中定义的
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:abstractions="clr-namespace:RoundedBoxView.Forms.Plugin.Abstractions;assembly=RoundedBoxView.Forms.Plugin.Abstractions"
xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
x:Class="LikeIT.forms.App">
<Application.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="TwoButtonTopBarTemplate">
...
</ControlTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>
谢谢。
答案 0 :(得分:0)
public App()
{
MainPage = new MainPage();
InitializeComponent();
}
应该是
public App()
{
InitializeComponent();
MainPage = new MainPage();
}