Caliburn-Micro / Caliburn.Micro

A small, yet powerful framework, designed for building applications across all XAML platforms. Its strong support for MV* patterns will enable you to build your solution quickly, without the need to sacrifice code quality or testability.
http://caliburnmicro.com/
MIT License
2.79k stars 776 forks source link

Caliburn Micro for Maui #831

Closed schovan closed 1 year ago

schovan commented 1 year ago

I started experimenting with Maui and found that other MVVM frameworks for MAUI are either unusable (haven't features that I want) or bugged. Can I somewhere download alpha / beta build for MAUI and test it? Do you plan some pre-release / when ?

406841895 commented 1 year ago

image The color of the title bar is not normal, and the background color of the navigation bar is wrong. The program crashes when exiting debug for the first time

schovan commented 1 year ago

@406841895 Is this a version you made it by yourself or you downloaded it somewhere?

vb2ae commented 1 year ago

Not sure what you are asking?

schovan commented 1 year ago

@vb2ae me neither :-) maybe caliburn micro 5 beta? Is this https://github.com/Caliburn-Micro/Caliburn.Micro/releases/tag/5.0.19-beta%2B7e85e48931 what I should use?

vb2ae commented 1 year ago

yes the caliburn micro 5 beta has a maui version. would love any feedback. It is available in our myget feed

406841895 commented 1 year ago

@406841895 Is this a version you made it by yourself or you downloaded it somewhere?

This app is written based on the Microsoft example, I made a mistake and now the style is fine, but I don't know how to configure the IOC container

406841895 commented 1 year ago

yes the caliburn micro 5 beta has a maui version. would love any feedback. It is available in our myget feed

In the maui version, why is there no AppBootstrapper, and how do I configure the IOC container SimpleContainer

KasperSK commented 1 year ago

Try looking at this sample for inspiration on how to setup Caliburn micro with MAUI: MAUI Sample

KasperSK commented 1 year ago

I am aware of a bug the I need to get around to fixing it has to do with the viewlocator and namespace mappings. If you run into issues finding views it is because CM is trying to use Activity as a suffix instead of view.

schovan commented 1 year ago

@KasperSK Has anyone tested if dependency injection really works for MAUI? Looks like it only works for parametless constructor. Look at this file for example: https://github.com/Caliburn-Micro/Caliburn.Micro/blob/master/src/Caliburn.Micro.Platform/Platforms/Maui/Windows/CaliburnApplication.cs Or am I using a wrong version? Is there any hidden version where is it implemented? Or does depencency injection in MAUI with Caliburn require some special setup?

Edit: I made some experiments and made it working. I requires some special setup, that is not included in the example app. The setup needs to be done for every platform. I made it for Windows and Android. I don't know, how to do it for Apple and Tizen. This is for Windows, I hope it is a correct approach: https://gist.github.com/schovan/3ba38aaf210a492c2f52a74a46a4d4de

KasperSK commented 1 year ago

@schovan I have not made any effort to integrate with the IoC in MAUI, but there are several ways to achieve this (like in your edit).

I think we need to make a setup sample that uses IoC, as one of the more advanced features.

vb2ae commented 1 year ago

for android

[Application] public class MainApplication : Caliburn.Micro.Maui.CaliburnApplication { public MainApplication(IntPtr handle, JniHandleOwnership ownership) : base(handle, ownership) { Initialize(); }

   protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

   protected override void Configure()
   {
       base.Configure();
   }

   protected override IEnumerable<Assembly> SelectAssemblies()
   {
       return new List<Assembly>() { typeof(App).Assembly };
   }

   protected override object GetInstance(Type service, string key)
   {
       return MauiProgram.builder.Services.BuildServiceProvider().GetService(service);
   }

   protected override IEnumerable<object> GetAllInstances(Type service)
   {
       return new List<object>() { MauiProgram.builder.Services.BuildServiceProvider().GetService(service) };
   }

}

vb2ae commented 1 year ago

For Ios, and Mac Catatlyst

[Register("AppDelegate")]
public class AppDelegate : Caliburn.Micro.Maui.CaliburnApplicationDelegate
{
    public AppDelegate()
    {
        Initialize();
    }

    protected override object GetInstance(Type service, string key)
    {
        return MauiProgram.builder.Services.BuildServiceProvider().GetService(service);
    }

    protected override IEnumerable<object> GetAllInstances(Type service)
    {
        return new List<object>() { MauiProgram.builder.Services.BuildServiceProvider().GetService(service) };
    }

    protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Ryovenly commented 1 year ago

Hi, Caliburn.Micro was using for my enterprise app in WPF so I'm using Caliburn.Micro.Maui for migration and with the setup it's works good. But I'm trying to do the ShellView like the tutorial for WPF . However with Window it does not work and causes a bug. Window seems to work with C# code and with Xaml there is no example.

<?xml version="1.0" encoding="utf-8" ?>
<Window xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Formation.Views.ShellView"
             Title="ShellView">

    <!--With WPF-->
    <!--<Grid>
        <ContentControl x:Name="ActiveItem" Margin="20"/>
    </Grid>-->

    <ContentPage x:Name="ActiveItem"></ContentPage>

</Window>

Do you know how to make it work with the ShellView or maybe it's not yet implemented for MAUI. Otherwise how to change view with another page?

vb2ae commented 1 year ago

Closing ticket moved shellview to new issue