How to create / use control library for Maui

Lloyd Sheen 1,486 Reputation points
2023-09-11T16:39:52.3433333+00:00

I am in the process of getting rid of 3rd party (paid) controls. I am also adding several controls that I want to use in apps. What I would like to know is how to accomplish this by creating a control library which can be added to the app that is being changed.

This would eventually mean that I would either a project that can be added to the solution of apps that are going to use it or it can be added as in NuGet.

Developer technologies .NET .NET MAUI
Developer technologies Visual Studio Other
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-09-12T02:22:53.6+00:00

    Hello,

    After investigation, you could do this by encapsulating custom controls into .NET MAUI class library.

    Please refer to the following steps:

    For creating:

    Step 1. Created .NET MAUI Class Library project in Visual Studio. In this example, the default MauiLib1 is used as the project name.

    Step 2. Add your custom controls in MauiLib1. In this example, I add a custom Entry control.

    public class CusEntry : Entry
    {
        public CusEntry()
        {
            this.Text = "test";
            this.FontSize = 70;
        }
    }
    

    For using:

    Step 3. Right-click the Solution 'MauiLib1' in Solution Explorer, and click add -> New Project to create new MAUI project.

    Step 4. Right-click on Dependencies in the MAUI project and select Add Project Reference, and check your Class Library project.

    Step 5. Use the custom Entry in MAUI xaml file.

    xmlns:myLib="clr-namespace:MauiLib1;assembly=MauiLib1"
    
    <myLib:CusEntry/>
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.