shub1409

Firstly I am very new to xamarin, and I am using visual studio 2017 and I have encountered a problem in how to work with cross platforms in xamarin. The Cross-Platform has two forms first is a blank app and second is master details. I select the blank app and see that there are three axml files- MainPage.axml, Toolbar.axml, Tabbar.axml. Can someone tell me in which file I add buttons, textfields to able to show the design of my app.

Posts

  • SzbestaSzbesta Member ✭✭✭

    You dont have to add the buttons to any of these pages you can create your own pages and fill them with the controls you desire.
    Which pages you create and what controls you put into them is up to you!

  • shub1409shub1409 Member ✭✭
    edited June 21
    using Android;
    using Android.App;
    using Android.Content;
    using Android.Graphics;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Java.Lang;
    
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;
    
    namespace O_Notification
    {
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class NotificationHelper : ContentPage
    {
        public NotificationHelper()
        {
            InitializeComponent();
        }
        public static class String
        {
            public const int noti_channel_default = 2131165200;
        }
    
        public const string PRIMARY_CHANNEL = "default";
        NotificationManager manager;
        NotificationManager Manager
        {
            get
            {
                if (manager == null)
                {
                    manager = (NotificationManager)GetSystemService(NotificationService);
                }
                return manager;
            }
        }
    
        int SmallIcon => Android.Resource.Drawable.StatNotifyChat;
    
        public NotificationHelper(Context context) : base(context)
        {
            var chan1 = new NotificationChannel(PRIMARY_CHANNEL,
                    GetString(String.noti_channel_default), NotificationImportance.Default);
            chan1.LightColor = Android.Graphics.Color.Green;
            chan1.LockscreenVisibility = NotificationVisibility.Private;
            Manager.CreateNotificationChannel(chan1);
    
        }
    
        public Notification.Builder GetNotification1(String title, String body)
        {
            return new Notification.Builder(ApplicationContext, PRIMARY_CHANNEL)
                     .SetContentTitle(title)
                     .SetContentText(body)
                     .SetSmallIcon(SmallIcon)
                     .SetAutoCancel(true);
        }
        public void Notify(int id, Notification.Builder notification)
        {
            Manager.Notify(id, notification.Build());
        }
    }
    }
    

    This is NotificationHelper.xaml.cs Class, In this I am getting errors in GetSystemService, NotificationService, GetString saying 'GetSystemService does not exist in the current context' and same is for NotificationService and GetString.

    The base keyword is not working saying 'ContentPage does not contain a constructor that takes 1 argument' and also the GetNotification1(String title, String body) saying" 'NotificationHelper.String': static types cannot be used as parameters' ".
    The whole code is a mess, I cannot resolve these errors.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University, Xamarin Moderator Xamurai
    edited June 27

    You are mixing Xamarin.Android code with Xamarin.Forms code. So yes, the whole code is a mess. Is this a template? It is not any starter template I have seen.

    Please go over this getting started guide for Xamarin Forms: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/get-started/

    When working with Xamarin Forms, you are dealing with multiple projects that each have some restrictions as to what code can be put in that project. There is a Core project that you can put Xamarin.Forms controls and pages in as well as any code that is identical for all of the platform projects in your solution. Then there are projects for each platform you are supporting, e.g. Android, iOS, UWP, etc. Xamarin Forms code and types should go in the Core project, while any platform specific code, i.e. code that would work in Android but not in iOS, needs to go in the platform specific project, i.e. in the Android project for code that would work in Android but not in iOS, etc.

    This is NotificationHelper.xaml.cs Class, In this I am getting errors in GetSystemService, NotificationService, GetString saying 'GetSystemService does not exist in the current context' and same is for NotificationService and GetString.

    What I see in your code above is Android specific code (GetSystemService, NotificationService, GetString) in a ContentPage, which is a Xamarin.Forms type. This leads me to believe that you are putting Android specific code in the common Core project that has a restriction that no platform specific code can be directly put in that project, hence the 'GetSystemService does not exist in the current context' errors.

    (More correctly, platform specific cade can be put into the core project IF the core project is a Shared project type, not a PCL or .NET Standard project, but even then the Platform specific code would have to be bounded by #ifdef/#endif compiler directives, which are not present in your code above.)

    The base keyword is not working saying 'ContentPage does not contain a constructor that takes 1 argument' and also the GetNotification1(String title, String body) saying" 'NotificationHelper.String': static types cannot be used as parameters' ".
    The whole code is a mess, I cannot resolve these errors.

    Yes, you have a base class of ContentPage which indeed does not have a constructor that takes one parameter. This is again because you are trying to subclass a Xamarin.Forms type, ContentPage, but using Android specific code added to the subclass, and implementing a constructor with code copied from an Android type.)

    I highly recommend Xamarin University for instructor led classes that start from the basics of programming with C# up to using Xamarin at an advanced level.

  • shub1409shub1409 Member ✭✭

    Thanks, Sir but I already corrected that error and I Just dropped this project and creating a new one. And try to create a new one but I didn't find one on the internet so I want you to suggest me where I can get the code for this project.
    And about that mixing thing I already corrected that by first understanding the difference between Xamarin Android and Xamrin forms, I have created some small projects in the xamarin forms to understand it better.
    The course you were talking about is helpful or just like some tutorial videos on youtube?

  • SzbestaSzbesta Member ✭✭✭

    And try to create a new one but I didn't find one on the internet so I want you to suggest me where I can get the code for this project.

    You want to create a project but you cant find it on the internet are you suggesting you are unable to create a blank project and make it into an App. If thats the case stop developing.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University, Xamarin Moderator Xamurai
    edited June 27

    @shub1409 said:
    The course you were talking about is helpful or just like some tutorial videos on youtube?

    from the Xamarin University link provided earlier:

    Xamarin University is a live, interactive, mobile development training led by Xamarin experts. Start learning Xamarin from the people who know it best. With over 80 courses covering 10 tracks, Xamarin University is the best training offering that will keep you up-to-date to stay ahead in this fast paced mobile world.

Sign In or Register to comment.