Stylet.Avalonia
0.4.1
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
<PackageReference Include="Stylet.Avalonia" Version="0.4.1" />
paket add Stylet.Avalonia --version 0.4.1
#r "nuget: Stylet.Avalonia, 0.4.1"
// 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
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.将nuget
包XamlNameReferenceGenerator
移除(新版本已内置)
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 | Versions 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. |
-
net6.0
- Avalonia (>= 11.0.2)
- System.Reactive (>= 6.0.0)
-
net7.0
- Avalonia (>= 11.0.2)
- System.Reactive (>= 6.0.0)
-
net8.0
- Avalonia (>= 11.0.2)
- System.Reactive (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.