Stylet.Avalonia 0.4.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Stylet.Avalonia --version 0.4.1                
NuGet\Install-Package Stylet.Avalonia -Version 0.4.1                
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="Stylet.Avalonia" Version="0.4.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Stylet.Avalonia --version 0.4.1                
#r "nuget: Stylet.Avalonia, 0.4.1"                
#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 Stylet.Avalonia as a Cake Addin
#addin nuget:?package=Stylet.Avalonia&version=0.4.1

// Install Stylet.Avalonia as a Cake Tool
#tool nuget:?package=Stylet.Avalonia&version=0.4.1                

Project Icon Stylet.Avalonia

英文文档

请注意本项目需要 AvaloniaUI 版本 >= 0.11.0-preview

项目介绍

Stylet.Avalonia是原来Stylet项目对AvaloniaUI 框架的适配。具体介绍请查看Stylet项目介绍

快速开始

第一步:创建一个AvaloniaUI框架

第二步:nuget 管理器安装 Stylet.Avalonia

第三步:创建ShellViewModel类,以及Avalonia Window类型名为ShellView的窗口组件,其内容如下【其实啥也没动】

  • ShellViewModel.cs
public class ShellViewModel
{
    
}
  • ShellView.axaml
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="Avalonia.NETCoreApp1.ShellView"
        Title="ShellView">
    Welcome to Avalonia!
</Window>
  • ShellView.axaml.cs
public partial class ShellView : Window
{
    public ShellView()
    {
        InitializeComponent();
    }
}

第四步:修改App.axaml文件,其内容如下:

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    		 xmlns:s="https://github.com/sealoyal2018/stylet.avalonia"
             xmlns:local="using:Avalonia.NETCoreApp1"
             x:Class="Avalonia.NETCoreApp1.App"
    RequestedThemeVariant="Light">
    <Application.Styles>
        <FluentTheme/>
    </Application.Styles>
</Application>

第五步:找到并打开App.axaml.cs文件,使其继承于StyletApplication<T>其中T为任一ViewModel,当前内容如下

public partial class App : StyletApplication<ShellViewModel>
{
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
        base.Initialize(); // 初始化stylet,不能去掉
    }
}

第七步:运行。快乐的写代码吧!

其他

更多资料点击这里跳转查看。同时,可以查看本仓库中存放的示例项目。

从 0.0.1升级?

请将avalonia 升级到11.x,升级指南

0.将nugetXamlNameReferenceGenerator移除(新版本已内置)

1.找到并打开App.axaml文件,移除AppBootstrapper资源,即:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <s:ApplicationLoader>
                <s:ApplicationLoader.Bootstrapper>
                    <local:AppBootstrapper  />
                </s:ApplicationLoader.Bootstrapper>
            </s:ApplicationLoader>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

2.找到并打开App.axaml.cs文件,使其继承于StyletApplication<T>, 此时App.axaml.cs成为了原来AppBootstrapper<ShellViewModel>, 将原来的AppBootstrapper.cs的内容移到App.axaml.cs文件中即可。

其注意App.axaml.cs文件内Initialize()方法必须调用base.Initialize();

Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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. 
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
0.5.1 119 9/23/2024
0.5.0 95 8/2/2024
0.4.2 157 2/5/2024
0.4.1 149 12/18/2023
0.4.0 160 12/7/2023
0.3.0 165 11/14/2023
0.2.0 221 8/3/2023
0.1.2 237 10/1/2022
0.1.1 208 10/1/2022
0.1.0 211 10/1/2022