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.8k stars 778 forks source link

"ActiveItem" method missing in v4.0.105-alpha #697

Closed reiniellematt closed 4 years ago

reiniellematt commented 4 years ago

I am currently trying to use Caliburn.Micro with WPF in .NET Core 3.1. While creating a simple "single page" application wherein I only have one window (ShellView) and I will be using UserControls to be the pages.

Platform: Windows 10 Home 1909 64-bit

Steps on recreating the issue:

  1. Create a new .NET Core 3.1 WPF project.
  2. Add Caliburn.Micro pre-release into project.
  3. Install Microsoft.Extensions.DependencyInjection, Microsoft.Extensions.Options.ConfigurationExtensions, and Microsoft.Extensions.Configuration.Json NuGet packages to be used as the DI for the project.
  4. Setup App.xaml
    <Application x:Class="CaliburnDI.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:CaliburnDI">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <local:Bootstrapper x:Key="Bootstrapper"/>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    </Application>
  5. Setup Bootstrapper.cs
    
    using Caliburn.Micro;
    using CaliburnDI.ViewModels;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Windows;

namespace CaliburnDI { public class Bootstrapper : BootstrapperBase { public IServiceProvider ServiceProvider { get; set; } public IConfiguration Configuration { get; set; }

    public Bootstrapper()
    {
        Initialize();
    }

    protected override void OnStartup(object sender, StartupEventArgs e)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", false, true);

        Configuration = builder.Build();

        var serviceCollection = new ServiceCollection();
        ConfigureServices(serviceCollection);

        DisplayRootViewFor<ShellViewModel>();
    }

    private void ConfigureServices(IServiceCollection services)
    {
        // UI services
        services.AddSingleton<IEventAggregator, EventAggregator>();
        services.AddSingleton<IWindowManager, WindowManager>();

        GetType().Assembly.GetTypes()
            .Where(type => type.IsClass)
            .Where(type => type.Name.EndsWith("ViewModel"))
            .ToList()
            .ForEach(viewModelType => services.AddTransient(
                viewModelType, viewModelType));
    }
}

}


6. Create Views and ViewModels folder. In the Views folder, add `ShellView.xaml` that is a Window. Then add a `HomeView.xaml` which is a UserControl.

7. Code for the `ShellViewModel.cs`

using Caliburn.Micro;

namespace CaliburnDI.ViewModels { public class ShellViewModel : Conductor { public ShellViewModel() { ActivateItem(IoC.Get()); } } }


Then the error shows up as *The name 'ActiveItem' does not exist in the current context*
reiniellematt commented 4 years ago

I read the code and I saw that only ActiveItemAsync is available. I guess ActiveItem will not be used anymore.

mvermef commented 4 years ago

This was part of a move towards async

schvila commented 4 years ago

I have similar experience. Try use: await ActivateItemAsync(IoC.Get(), CancellationToken.None);