Xamarin 对象实例化为空

问题描述

我有一个代码实例化时始终为空的 ContentPage。 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"
         xmlns:d="http://xamarin.com/schemas/2014/forms/design"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
         x:Class="galaxy.Views.dispatchFormViewer"
         Visual="Material"
         BackgroundColor="{DynamicResource PageBackground}"
         xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOsspecific;assembly=Xamarin.Forms.Core"
         ios:Page.UseSafeArea="True">
<ContentPage.Content>
    <ScrollView>
        <StackLayout x:Name="FormStackLayout" Padding="5"></StackLayout>
    </ScrollView>
</ContentPage.Content> </ContentPage>

后面的代码是(仅限字段、属性和构造函数):

  [XamlCompilation(XamlCompilationoptions.Compile)]
    public partial class dispatchFormViewer : ContentPage
    {
        private int ExpandableCount;
        private DateTime CreationDate;
        private int FormID;
        private int DraftID;
        private int JobID;
        private int NewStatus;
        private bool IsCancellation { get; set; }
        public bool IsComplete { get; set; }
        public bool IsMediaTransition { get; set; }

        public dispatchFormViewer()
        {
            InitializeComponent();
        }

        public dispatchFormViewer(ContentView mainView,int formID,int draftID,int jobID,bool cancellation,int newStatus,DateTime startDate)
        {
            InitializeComponent();
            FormStackLayout.Children.Add(mainView);
            FormID = formID;
            DraftID = draftID;
            JobID = jobID;
            IsCancellation = cancellation;
            NewStatus = newStatus;
            CreationDate = startDate;
            ExpandableCount = 1;
        }

然而即使是一个简单的:

var navPage = new dispatchFormViewer();

在 navPage 对象中返回 null。我看不到任何错误输出中也没有任何错误提示我有一个控件,它的工作原理几乎相同。

我对构造函数如何返回 null 感到困惑!我从另一个开发人员那里继承了一个 xamarin 项目,但我之前从未参与过该项目,所以不确定从哪里开始寻找。

这发生在 Android 模拟器上。

提前致谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)