Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caliburn Micro for Maui #831

Closed
schovan opened this issue Oct 5, 2022 · 15 comments
Closed

Caliburn Micro for Maui #831

schovan opened this issue Oct 5, 2022 · 15 comments

Comments

@schovan
Copy link

schovan commented Oct 5, 2022

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
Copy link

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
Copy link
Author

schovan commented Oct 13, 2022

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

@vb2ae
Copy link
Member

vb2ae commented Oct 13, 2022

Not sure what you are asking?

@schovan
Copy link
Author

schovan commented Oct 13, 2022

@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
Copy link
Member

vb2ae commented Oct 13, 2022

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

@406841895
Copy link

@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
Copy link

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
Copy link
Member

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

@KasperSK
Copy link
Member

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
Copy link
Author

schovan commented Nov 6, 2022

@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
Copy link
Member

KasperSK commented Nov 7, 2022

@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
Copy link
Member

vb2ae commented Nov 13, 2022

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
Copy link
Member

vb2ae commented Nov 13, 2022

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
Copy link

Ryovenly commented Feb 1, 2023

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
Copy link
Member

vb2ae commented Apr 22, 2023

Closing ticket moved shellview to new issue

@vb2ae vb2ae closed this as completed Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants