【问题标题】:send some paramters to detail from master in xamarin forms以 xamarin 形式从 master 发送一些参数到 detail
【发布时间】:2026-01-15 05:00:02
【问题描述】:

我正在尝试在 xamarin 表单中创建母版页详细信息。简单的逻辑,用户将单击导航页面中的按钮,然后它将一些参数发送到详细信息页面,并根据该参数我将从休息服务绑定列表视图,但是我无法将参数发送到详细信息页面,我正在使用此方法但仍然出现错误

   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 中禁用了链接器,但还是一样,没有任何变化。

【问题讨论】:

  • 你遇到了什么错误?
  • 对不起,我忘了写,错误是“System.MissingMethodException: Default constructor not found for type paux.Pages.PageDetay”
  • 如果可以请分享完整代码。我无法复制那个问题。
  • 由于您在 XAML 中指定详细信息,因此它正在尝试使用缺少的默认(无参数)构造函数自动创建副本。

标签: c# android xamarin xamarin.ios xamarin.forms


【解决方案1】:

我的问题与标题有关,我的 Xaml MasterPage 中缺少标题。在你的 lstViewMaster.xaml 中有标题吗?

<?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">

【讨论】:

    最近更新 更多