Abdrakov.Solutions.Avalonia 1.1.12

There is a newer version of this package available.
See the version list below for details.
dotnet add package Abdrakov.Solutions.Avalonia --version 1.1.12
NuGet\Install-Package Abdrakov.Solutions.Avalonia -Version 1.1.12
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Abdrakov.Solutions.Avalonia" Version="1.1.12" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Abdrakov.Solutions.Avalonia --version 1.1.12
#r "nuget: Abdrakov.Solutions.Avalonia, 1.1.12"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Abdrakov.Solutions.Avalonia as a Cake Addin
#addin nuget:?package=Abdrakov.Solutions.Avalonia&version=1.1.12

// Install Abdrakov.Solutions.Avalonia as a Cake Tool
#tool nuget:?package=Abdrakov.Solutions.Avalonia&version=1.1.12

Abdrakov.Solutions

About:

This is the main repo for all the Abdrakov projects. This project fully supports Prism features and MVVM pattern. The original README source: https://github.com/CrackAndDie/Abdrakov.Solutions/blob/main/README.md

Getting started:

First steps:

When you created your WPF app you should rewrite your App.xaml and App.xaml.cs files as follows:

<engine:AbdrakovApplication x:Class="YourNamespace.App"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:local="clr-namespace:YourNamespace"
                            xmlns:engine="clr-namespace:Abdrakov.Engine.MVVM;assembly=Abdrakov.Engine">
</engine:AbdrakovApplication>
namespace YourNamespace
{
    public partial class App : AbdrakovApplication
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
        }

        protected override Window CreateShell()
        {
            var viewModelService = Container.Resolve<IViewModelResolverService>();
            viewModelService.RegisterViewModelAssembly(Assembly.GetExecutingAssembly());

            return base.CreateShell();
        }

        protected override void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            base.RegisterTypes(containerRegistry);
            containerRegistry.RegisterInstance(new BaseWindowSettings()
            {
                ProductName = "Tests",
                LogoImage = "pack://application:,,,/Abdrakov.Tests;component/Resources/AbdrakovSolutions.png",
            });
            containerRegistry.RegisterSingleton<IBaseWindow, MainWindowView>();
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            base.ConfigureModuleCatalog(moduleCatalog);
            // ...
        }
    }
}

As you can see there is a BaseWindowSettings registration that gives you quite flexible setting of your Window (in this example we use MainWindowView from Abdrakov.CommonWPF namespace). Here you can see all the available settings of the Window:

  • LogoImage - Path to the logo image of your app like "pack://application:,,,/Abdrakov.Tests;component/Resources/AbdrakovSolutions.png"
  • ProductName - Title text that will be shown on the window header
  • MinimizeButtonVisibility - How should be Minimize button be shown (default is Visible)
  • MaxResButtonsVisibility - How should be Maximize and Restore buttons be shown (default is Visible)
  • WindowProgressVisibility - How should be Progress state be shown (default is Visible)
  • SmoothAppear - How sould be window appeared (true - smooth, false - as usual)

You can use Regions.MAIN_REGION to navigate in the MainWindowView:

internal class MainModule : IModule
{
    public void OnInitialized(IContainerProvider containerProvider)
    {
        var region = containerProvider.Resolve<IRegionManager>();
        // the view to display on start up
        region.RegisterViewWithRegion(Regions.MAIN_REGION, typeof(MainPageView));
    }

    public void RegisterTypes(IContainerRegistry containerRegistry)
    {
        containerRegistry.RegisterForNavigation<MainPageView>();
    }
}

Preview window:

You can create your own preview window using Abdrakov.Solutions. Your preview window has to implement IPreviewWindow interface. Here is the sample preview window that shows up for 4 seconds:

public partial class PreviewWindowView : Window, IPreviewWindow
{
    private DispatcherTimer timer;
    public PreviewWindowView()
    {
        InitializeComponent();

        timer = new DispatcherTimer()
        {
            Interval = TimeSpan.FromSeconds(4),
        };
        timer.Tick += (s, a) => { CallPreviewDoneEvent(); };
        timer.Start();
    }

    public void CallPreviewDoneEvent()
    {
        timer.Stop();
        var cont = (Application.Current as AbdrakovApplication).Container;
        cont.Resolve<IEventAggregator>().GetEvent<PreviewDoneEvent>().Publish();
        this.Close();
    }
}

Your preview window should be also registered like this:

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
    base.RegisterTypes(containerRegistry);

    containerRegistry.RegisterSingleton<IPreviewWindow, PreviewWindowView>();

    // ...
}

Registered Window under IBaseWindow interface will be shown up after PreviewDoneEvent event call.

Theme registrations:

Abdrakov.Solutions supports realtime theme change (Dark/Light) and flexible colors (brushes) registrations. Here is the sample code to register IAbdrakovThemeService in your App (if you don't want the theme change service in your project you can skip this registration):

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
    base.RegisterTypes(containerRegistry);
    // ...
    containerRegistry.RegisterSingleton<IAbdrakovThemeService, AbdrakovThemeService>();
}

Using the IAbdrakovThemeService you can change an App's theme in realtime using method ApplyBase(isDark) and get current theme using property IsDark.
Here is the sample code to register themes and colors in your App:

private void ConfigureApplicationVisual()
{
    Resources.MergedDictionaries.Add(new AbdrakovBundledTheme()
    {
        IsDarkMode = true,  // default theme on app startup
        ExtendedColors = new Dictionary<string, ColorPair>()  // your external color registrations
        {
            { "Test", new ColorPair(Colors.Red, Colors.Purple) },
        }
    }.SetTheme());
}

Every color registration gives you dynamic Brush and Color (like TestBrush and TestBrushColor).

Here is the names that should be registered in your app:

  • TextForeground - The colors of the product name and window buttons
  • WindowStatus - The colors of the window progress indicator
  • Window - The colors of the window and window header backgrounds

ConfigureApplicationVisual could be called in OnStartup overrided method like this:

protected override void OnStartup(StartupEventArgs e)
{
    ConfigureApplicationVisual();
    //...
    base.OnStartup(e);
    //...
}

If you won't register any of the theme it will be gererated automaticaly by reversing colors of the existing theme.
Registered colors and brushes could be used as DynamicResources like that:

<Rectangle Fill="{DynamicResource TestBrush}"/>

There is also a ThemeChangedEvent event that is called through IEventAggregator with ThemeChangedEventArgs. You can subscribe like this (IEventAggregator is already resolved in ViewModelBase):

(Application.Current as AbdrakovApplication).Container.Resolve<IEventAggregator>().GetEvent<ThemeChangedEvent>().Subscribe(YourMethod);

Localization:

Abdrakov.Solutions also provides you a great realtime localization solution. To use it you should create a folder Localization in your project and make some changes in your App.xaml.cs file:

public partial class App : AbdrakovApplication
{
    protected override void OnStartup(StartupEventArgs e)
    {
        LocalizationManager.InitializeExternal(Assembly.GetExecutingAssembly(), new ObservableCollection<Language>()
        {
            new Language() { Name = "EN" },
            new Language() { Name = "RU" },
        });  // initialization of LocalizationManager static service
        // ...
        base.OnStartup(e);
    }
}

In the Localization folder you create Resource files with translations and call it as follows - "FileName"."Language".resx (Gui.resx or Gui.ru.resx). Default resource file doesn't need to have the "Language" part.

Now you can use it like this:

<TextBlock Text="{LocalizedResource MainPage.TestText}"
            Foreground="{DynamicResource TextForegroundBrush}" />

To change current localization you can change LocalizationManager.CurrentLanguage property like this:

LocalizationManager.CurrentLanguage = CultureInfo.GetCultureInfo(item.Name.ToLower());

In this examle item is an instance of Language class.

Window progress indicator:

There is also a progress indicator on the MainWindowView header that could be used to show user current window status. To handle this status you can resolve IWindowProgressService service (or use WindowProgressService property of ViewModelBase) and use AddWaiter() method to add waiter to the service and RemoveWaiter() when the job is done. You can also handle WindowProgressChangedEvent by yourself using IEventAggregator.

Logging:

To log your app's work you can resolve ILoggingService that is just an adapter of Log4netLoggingService or use LoggingService property of ViewModelBase.

You can find the log file in you running assembly directory called cadlog.log.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.17 109 2/3/2024
1.1.16 90 1/24/2024
1.1.15 94 1/18/2024
1.1.14 93 1/15/2024
1.1.13 115 12/31/2023
1.1.12 117 12/15/2023
1.1.11 98 12/14/2023
1.1.10 92 12/14/2023