Forum Xamarin Cross Platform with Xamarin

How to use a C# class in a ContentPage

I've put several functions into a separate C# class named "PCLHelper" because I didn't want to pollute my ContentPage.

But now the functions of the PCLHelper class aren't visible in my ContentPage.

I've tried adding "using PCLHelper;" but that didn't do it.

How could I do this?

Thank you.



  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Post your code
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    The bigger question is: Why do you have so much work in your page code behind?
    That raises a flag that makes me think you aren't following good MVVM practices and have a lot of logic in code-behind instead of in the ViewModel.

  • LalaRiverLalaRiver DEMember ✭✭
    using System;
    using System.Linq;
    namespace MyApp
       public  class PCLHelper
            public bool Version2IsHigher(string uVersion1, string uVersion2)

    And I to use it from

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Threading.Tasks;
    using Xamarin.Forms;
    using Version.Plugin;
    using System.Net.Http;
    namespace MyApp
        public partial class PageCanvas : ContentPage
            public PageCanvas()
            async void pTellUpdate()
                    string sLocalVersion = CrossVersion.Current.Version;
                    //some code
                    if (Version2IsHigher(sLocalVersion, sInternetVersion))
  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think it should be static

    public static bool Version2IsHigher(string uVersion1, string uVersion2)
  • LalaRiverLalaRiver DEMember ✭✭

    I changed it to your suggestion, but when I try to use


    I get the error "Alias PCLHelper wasn't found", and without "PCLHelper::", it's also not working.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    What does it happens if you write "PCLHelper." in your code? Do you have some suggestions?

    Have you tried to clean and rebuild?

  • LalaRiverLalaRiver DEMember ✭✭

    No, I don't get any suggestions, the IDE tells me "Alias PCLHelper not found".
    Yes, I tried to rebuild.

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    Are both classes in the same project? If not do you have a reference to the project with the helper class in the project with the code behind?
Sign In or Register to comment.