András Tóth‘s professional blog
banditoth.net

Hey there 👋, I’m banditoth a .NET MAUI developer from Hungary.
I write about software development with .NET technologies.

You can find me on:
LinkedIn | Github | StackOverflow | X / Twitter | Threads

Tag: maui

  • Forms.RecurrenceToolkit is discontinued

    This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    Just as Xamarin.Forms is changing to a .NET MAUI, banditoth.Forms.RecurrenceToolkit will also undergo a change. As of today, I do not plan to develop any new functionality in the aforementioned package. Some parts of the package will be developed for .NET MAUI compatibility. You will be able to find the new packages in the future with the banditoth.MAUI prefix, which will also be available on GitHub.
    I would like to thank you for the more than 2700 downloads.
    Bug fixes will continue to be made, so if someone actually uses this for a live application, in that case no worries.

    Let’s look at some statistics. The most popular package was MVVM with a total of 623 downloads. This was followed by the Logging package with 459 downloads. The Multilanguage and Converters packages were similarly successful, with around 430 downloads.

    I will be back soon with MAUI packages 😉

  • .NET MAUI RC1 is available with VS for Mac support

    This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    Good news for .NET MAUI fans. We’ll soon have a stable version from the wonderful developers at Microsoft, but in the meantime, here we have the first RC version of .NET MAUI.
    There’s a lot of new features in this version, including integration with the Essentials package, much more customizable styles, etc.
    But today I want to talk about the most important thing for me, which is the support for Visual Studio for Mac. Well, it’s not so official yet, and it’s not so usable, but we can see progress. VS for Mac 2022 is no longer a stranger to MAUI projects. Unfortunately, I couldn’t get the debugging to work, but you can now start the project on almost any platform.

    Let’s use MAUI in Visual Studio 2022 for Mac

    First and most importantly, and I experienced it first hand.
    If the IDE you want to use throws the following errors:

    /usr/local/share/dotnet/sdk/6.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(5,5): Error NETSDK1147: To build this project, the following workloads must be installed: maui-maccatalyst
    To install these workloads, run the following command: dotnet workload install maui-maccatalyst (NETSDK1147) (ResxEditorMaui)
    
    /usr/local/share/dotnet/sdk/6.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(5,5): Error NETSDK1147: To build this project, the following workloads must be installed: maui-ios
    To install these workloads, run the following command: dotnet workload install maui-ios (NETSDK1147) (ResxEditorMaui)
    
    /usr/local/share/dotnet/sdk/6.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(5,5): Error NETSDK1147: To build this project, the following workloads must be installed: maui-android
    To install these workloads, run the following command: dotnet workload install maui-android (NETSDK1147) (ResxEditorMaui)
    

    And you can’t install the recommended packages because the following error is displayed:

    Workload ID android-aot is not recognized.
    

    Then be sure to install .NET version 6.0.3XX. You can do this from this url and select the appropriate processor architecture. https://github.com/dotnet/installer

    To check which version is installed, you can check in the terminal with the following paranncs:

    dotnet --info
    

    If you have installed the required version of .NET 6.0, issue the following command:

    sudo dotnet workload install maui
    

    You can then use MAUI in Visual Studio for Mac.

  • The easiest and best MVVM toolkit also for .NET MAUI.

    This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    Guys, this is unbelievable. Microsoft Community toolkit has added a tool that means you never have to worry about which MVVM framework you’re voting for. None can be as good as this one. It can be used not only for .NET MAUI, but also for other technologies (e.g. WPF). But before I sing your praises, let’s look at what this package has to offer us:

    Introducing CommunityToolkit.Mvvm

    First of all, you don’t need to implement INotifyPropertyChanged in ViewModels. And by that I mean not even its parent classes. Since this component is a code generator, it’s enough to make your classes partial, and the INotifyPropertyChanged implementation is done by it, instead of you. This means that your class will be supplemented with the best implementation so that you can easily use common methods like SetProperty in the setter branch of your properties. Okay, okay, but almost any MVVM framework could do this, and you didn’t even need to use a code generator, just simply derive from a parent class. I’ll do you one better: what if you didn’t have to write the setter and getter branches of the properties at all? What if the toolkit made them itself? If you could implement a property declaration from two lines of code?
    Well, that’s what makes this toolkit good: It does all that for you.

    And if that’s not enough, you don’t even have to bother creating Commands. The toolkit automatically creates a command for you from your methods.
    But let’s see how you can use it.

    Use CommunityToolkit.MVVM in .NET MAUI

    Let’s see what my ViewModel looked like before I used this toolkit:

    namespace Carloo.ViewModels.SignInPage
    {
        public partial class SignInPageViewModel : BaseViewModel
        {
            private Command signInCommand;
            public Command SignInCommand
            {
                get { return signInCommand ?? (signInCommand = new Command(() => _ = SignIn(), () => true)); }
            }
    
            private string userName;
            public string UserName
            {
                get { return userName; }
                set { SetProperty(ref userName, value, nameof(UserName)); }
            }
    
            private string password;
            public string Password
            {
                get { return password; }
                set { SetProperty(ref password, value, nameof(Password)); }
            }
    
            public SignInPageViewModel()
            {
    
            }
    
            private void SignIn()
            {
                try
                {
                    ...
                }
                catch (Exception ex)
                {
                    // todo error
                }
            }
        }
    }
    
    

    And now let’s see what this Toolkit can do with source code to make life easier:

    namespace Carloo.ViewModels.SignInPage
    {
        [INotifyPropertyChanged]
        public partial class SignInPageViewModel
        {
            [ObservableProperty]
            private string userName;
    
            [ObservableProperty]
            private string password;
    
            public SignInPageViewModel()
            {
    
            }
    
            [ICommand]
            private void SignIn()
            {
                try
                {
                    ...
                }
                catch (Exception ex)
                {
                    // todo error
                }
            }
        }
    }
    
    

    In other ways, however, Resharper also had the tools to provide similar simplicity for implementing MVVM. But if I remember correctly, it didn’t have all that. Like, say, that you could release PropertyChanged on a completely unrelated property, even with an attribute declaration, without writing code.

            [ObservableProperty]
            [AlsoNotifyFor(nameof(CanSignIn))]
            private string _userName;
    
            [ObservableProperty]
            [AlsoNotifyFor(nameof(CanSignIn))]
            private string _password;
    
    
            public bool CanSignIn { get => !string.IsNullOrWhiteSpace(UserName) && !string.IsNullOrWhiteSpace(Password); }
    

    Learn more

    I am very excited about using this tool in production environments. If you want to learn more about it, please visit the following pages:
    https://devblogs.microsoft.com/ifdef-windows/announcing-net-community-toolkit-v8-0-0-preview-1/
    https://docs.microsoft.com/en-gb/windows/communitytoolkit/mvvm/introduction

  • .NET MAUI: App.xaml, MainPage.xaml is missing from the project

    This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    .NET MAUI is still in beta so there are no final project templates to create a new MAUI application. The current project template omits the App.xaml, and MainPage.xaml files from the project (at least on mac), so we have to add them ourselves.

    Enable on Visual Studio, to show all files

    Enable showing all files

    And select the missing files, then right click on them, and add them to the project.

    Include the missing files to the project
  • Run .NET MAUI apps with Visual Studio for Mac

    This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    VS for Mac 17.0 Preview version is not yet supporting MAUI applications. But you can run them on macOS too, but you will need a terminal window for it!

    MAUI projects can not be set as a runnable project (yet)
    .NET 6 Xamarin and MAUl projects are not supported with this version of Visual Studio. The included target frameworks are not supported: net6.0-android|net6.0-ios|net6.0-maccatalyst
    

    If you are not familiar, how to set up your environment to start developing with .NET newest technology named MAUI, then read this article by me: https://www.banditoth.hu/2021/12/29/setup-net-maui-project-on-macos/

    Build and run on macOS

    Open up a terminal, and navigate next to your .sln file. Give out the following command:

    dotnet build YourSolutionName -t:Run -f net6.0-maccatalyst
    

    This will run your application on macOS. If you wish, you can change the last parameter to net6.0-android or net6.0-ios too.