### Install Avalonia Templates Source: https://caliburnmicro.com/documentation/AvaloniaUI Installs the Avalonia UI project templates using the .NET CLI. ```bash dotnet new install Avalonia.Templates ``` -------------------------------- ### Install .NET MAUI Workload Source: https://caliburnmicro.com/documentation/dotnet-maui Installs the necessary .NET MAUI workload for Visual Studio. Use this command if you don't have MAUI installed. ```bash dotnet workload install maui ``` -------------------------------- ### Example: Custom Namespace and View Mapping Source: https://caliburnmicro.com/documentation/custom-conventions This example demonstrates setting up a custom type mapping. It captures a namespace fragment and uses it to transform the source namespace to a target namespace, resolving a ViewModel to a View with a custom convention. ```csharp //Capture namespace fragment preceding "ViewModels." as "nsbefore" string subns = RegExHelper.NamespaceToRegEx("ViewModels."); string rxrep = RegExHelper.GetNamespaceCaptureGroup("nsbefore") + subns; //Output the namespace fragment after "Views." in the target namespace string rxtgt = @"Views.${nsbefore}"; ViewLocator.AddTypeMapping(rxrep, null, rxtgt); //Resolves: MyApp.Some.Name.Space.ViewModels.TestViewModel -> Views.MyApp.Some.Name.Space.TestView ``` -------------------------------- ### Custom Namespace Mapping Examples Source: https://caliburnmicro.com/documentation/custom-conventions Demonstrates custom namespace mappings for Spanish conventions and wildcard usage. These examples show how to resolve ViewModels to Views and vice-versa with custom namespace structures. ```csharp //Add support for Spanish namespaces ViewLocator.AddSubNamespaceMapping("ModelosDeVistas", "Vistas"); //Resolves: MiProyecto.ModelosDeVistas.Clientes.ClienteViewModel -> MiProyecto.Vistas.Clientes.ClienteView ViewModelLocator.AddSubNamespaceMapping("Vistas", "ModelosDeVistas"); //Resolves: MiProyecto.Vistas.Clientes.ClienteView -> MiProyecto.ModelosDeVistas.Clientes.ClienteViewModel //Wildcard subnamespace mapping ViewLocator.AddSubNamespaceMapping("*.ViewModels", "ExtLib.Views"); //Resolves: MyCompany.MyApp.SomeNamespace.ViewModels.CustomerViewModel -> ExtLib.Views.CustomerView ViewLocator.AddSubNamespaceMapping("ViewModels.*", "Views"); //Resolves: MyApp.ViewModels.Some.Name.Space.CustomerViewModel -> MyApp.Views.CustomerView ViewLocator.AddSubNamespaceMapping("MyApp.*.ViewModels", "ExtLib.Views"); //Resolves: MyCompany.MyApp.SomeNamespace.ViewModels.CustomerViewModel -> MyCompany.ExtLib.Views.CustomerView ``` -------------------------------- ### Get .NET Version Source: https://caliburnmicro.com/documentation/build Determine your installed .NET SDK version. This is useful for troubleshooting project loading issues. ```bash dotnet --version ``` -------------------------------- ### Install Caliburn.Micro Package Source: https://caliburnmicro.com/documentation/nuget Use this command in the Package Manager Console to install the Caliburn.Micro NuGet package. ```powershell PM> Install-Package Caliburn.Micro ``` -------------------------------- ### Applying Custom Window Settings Source: https://caliburnmicro.com/documentation/Tutorials/WPF/AddDialogToShellView Example of creating dynamic settings for a window, including startup location, resize mode, minimum width, title, and icon, before showing it using the WindowManager. ```csharp dynamic settings = new ExpandoObject(); settings.WindowStartupLocation = WindowStartupLocation.CenterOwner; settings.ResizeMode = ResizeMode.NoResize; settings.MinWidth = 450; settings.Title = "My New Window"; settings.Icon = new BitmapImage( new Uri( "pack://application:,,,/MyApplication;component/Assets/myicon.ico" ) ); IWindowManager manager = new WindowManager(); manager.ShowDialog( myViewModel, null, settings ); ``` -------------------------------- ### App.xaml with Bootstrapper Resource Source: https://caliburnmicro.com/documentation/configuration This XAML snippet shows how to integrate the HelloBootstrapper into the application's resources. This ensures the bootstrapper runs when the application starts. ```xaml ``` -------------------------------- ### Complete Bootstrapper Implementation Source: https://caliburnmicro.com/documentation/Tutorials/WPF/Bootstrapper A complete example of the Bootstrapper class, including necessary using statements, constructor, and the overridden OnStartup method for .Net 5.0. For .NetCore 3.1, an additional using statement for Caliburn.Micro might be required. ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Caliburn.Micro.Tutorial.Wpf.ViewModels; using System.Windows; namespace Caliburn.Micro.Tutorial.Wpf { public class Bootstrapper: BootstrapperBase { public Bootstrapper() { Initialize(); } protected override async void OnStartup(object sender, StartupEventArgs e) { await DisplayRootViewForAsync(typeof(ShellViewModel)); } } } ``` -------------------------------- ### Custom Namespace Mapping Examples Source: https://caliburnmicro.com/documentation/custom-conventions Illustrates various ways to use AddNamespaceMapping, including appending targets to sources, standard explicit mappings, one-to-many mappings, and wildcard mappings. ```csharp //"Append target to source" mapping //Null string or string.Empty passed as source namespace is special case to allow this //Note the need to prepend target namespace with "." to make this work ViewLocator.AddNamespaceMapping("", ".Views"); //Resolves: MyProject.Customers.CustomerViewModel -> MyProject.Customers.Views.CustomerView ``` ```csharp //Standard explicit namespace mapping ViewLocator.AddNamespaceMapping("MyProject.ViewModels.Customers", "MyClient1.Views"); //Resolves: MyProject.ViewModels.CustomerViewModel -> MyClient1.Views.CustomerView ``` ```csharp //One to many explicit namespace mapping ViewLocator.AddNamespaceMapping("MyProject.ViewModels.Customers", new string[] { "MyClient1.Views", "MyProject.Views" } ); //Resolves: MyProject.ViewModels.CustomerViewModel -> {MyClient1.Views.CustomerView, MyProject.Views.CustomerView } ``` ```csharp //Wildcard mapping ViewLocator.AddNamespaceMapping("*.ViewModels.Customers.*", "MyClient1.Customers.Views"); //Resolves: MyProject.ViewModels.Customers.CustomerViewModel -> MyClient1.Customers.Views.CustomerView // MyProject.More.ViewModels.Customers.MasterViewModel -> MyClient1.Customers.Views.MasterView // MyProject.ViewModels.Customers.More.OrderHistoryViewModel -> MyClient1.Customers.Views.OrderHistoryView ``` -------------------------------- ### Constructor Injection Example Source: https://caliburnmicro.com/documentation/simple-container Demonstrates constructor injection where a service (IWindowManager) is a required dependency for a class (ShellViewModel). The container resolves and injects the dependency upon construction. ```csharp public class ShellViewModel { private readonly IWindowManager _windowManager; public ShellViewModel(IWindowManager windowManager) { _windowManager = windowManager; } } ``` -------------------------------- ### Complete ShellViewModel Example Source: https://caliburnmicro.com/documentation/Tutorials/WPF/CategoryEditorHookup This is the complete ShellViewModel, incorporating the EditCategories method and the OnViewLoaded override for invoking the category editor on application startup. ```csharp using System.Threading; using System.Threading.Tasks; namespace Caliburn.Micro.Tutorial.Wpf.ViewModels { public class ShellViewModel : Conductor { protected async override void OnViewLoaded(object view) { base.OnViewLoaded(view); await EditCategories(); } public async Task EditCategories() { var viewmodel = IoC.Get(); await ActivateItemAsync(viewmodel, new CancellationToken()); } } } ``` -------------------------------- ### Example Markup for Conventions Source: https://caliburnmicro.com/documentation/conventions This XAML demonstrates how Message.Attach can be used to declare an action on a Button that references a TextBox element. ```xaml