以xamarin形式从master发送一些参数到detail
本文关键字:参数 detail xamarin master | 更新日期: 2023-09-27 17:52:54
我试图在xamarin表单中创建一个主页细节。简单的逻辑,用户点击导航页的按钮然后它会发送一些参数到细节页根据这些参数,我将从rest服务绑定一个listview,但我不能发送参数到细节页,我使用这个方法,但仍然得到错误
private void Button_OnClicked(object sender, EventArgs e)
{
var item = (Xamarin.Forms.Button)sender;
Navigation.PushAsync(new PageDetay(item.CommandParameter.ToString()));
}
我的主页是这样的
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="paux.Pages.PageMaster" xmlns:local="clr-namespace:paux;assembly=paux">
<MasterDetailPage.Master>
<ContentPage Title="My page">
<StackLayout Orientation="Vertical">
<ListView x:Name="lstViewMaster" RowHeight="36" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Button Text = "{Binding ad}" CommandParameter="{Binding no}" Clicked="Button_OnClicked"/>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<local:Pages.PageDetay/>
</MasterDetailPage.Detail>
</MasterDetailPage>
我的详情页是这样的
public PageDetay(string id)
{
InitializeComponent();
}
任何帮助都很感激,谢谢。错误就是
namespace paux.Pages {
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
public partial class PageMaster : global::Xamarin.Forms.MasterDetailPage {
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private global::Xamarin.Forms.ListView lstViewMaster;
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private void InitializeComponent() {
this.LoadFromXaml(typeof(PageMaster)); // this is source of the error
lstViewMaster = this.FindByName<global::Xamarin.Forms.ListView>("lstViewMaster");
}
}
}一些xamarin用户抱怨这个错误并写了这个https://forums.xamarin.com/discussion/25938/missingmethod-exception-default-constructor-not-found我在ios中禁用了链接器,但还是一样,没有任何变化。
我的问题与标题有关,我在Xaml MasterPage中缺少标题。在你的lstViewMaster中。你有标题吗?
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
...
Title="Your title">