![](/img/trans.png)
[英]Xamarin.Forms - KeyNotFoundException: The given key was not present in the dictionary C#
[英]The given key was not present in the dictionary x:Arguments Xamarin.Forms
我正在使用MasterDetailPage
。 在MasterDetailPage.Master
部分中,我手动创建了ListView
。 但是在MasterDetailPage.Detail
我正在使用TabbedPage
类型的其他Page
。 这个
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<local:HomePage2 />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
在页面顶部声明的local
变量。 查看有HomePage2
文件
xmlns:local="clr-namespace:TestProjectXamarin.View"
代码<local:HomePage2 />
向我显示编译错误
给定的键在字典中不存在
这是HomePage2文件.cs
public partial class HomePage2 : TabbedPage
{
public HomePage2(string btnName)
{
InitializeComponent();
Title = "Home Page";
//BindingContext = new HomePageViewModel();
}
}
.xaml
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:TestProjectXamarin.View"
x:Class="TestProjectXamarin.View.HomePage2">
<TabbedPage.Children>
<NavigationPage Title="Games" Icon="games">
<x:Arguments>
<views:GamesTab/>
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Movies" Icon="camera">
<x:Arguments>
<views:MoviesTab />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
如果我使用内置的MasterDetailPage
模板创建Xamarin.Forms
项目,则相同类型的代码可以工作。 我该如何解决这个问题?
最可能的原因是缺少无参数的构造函数 。
鉴于您似乎没有使用参数,建议您更改以下内容:
public HomePage2(string btnName)
至:
public HomePage2()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.