微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xamarin 对象实例化为空

如何解决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 举报,一经查实,本站将立刻删除。