虽说.net core3.0已经可以用于开发wpf和winform程序,可是遗憾的时目前这core下的wpf还是只能运行在windows下,想要在linux下运行wpf估计还要等一段时间。

Avaloniaui :

直接用官网的一句话来描述吧:A cross platform XAML Framework for .NET Framework, .NET Core and Mono

在树莓派 4 B上允许Avaloniaui 简单的步骤:

第一步:

烧录树莓派最新的系统Raspbian ,最新的Raspbian 下载地址

第二步:

Install curllibunwind8gettext and apt-transport-https. The curl and apt-transport-https often are up-to-date.

sudo apt-get install curl libunwind8 gettext apt-transport-https

下载.net core 3.0  arm32 运行时 最新的下载地址

curl -sSL -o dotnet.tar.gz https://download.visualstudio.microsoft.com/download/pr/0c5e013b-fa57-44dc-85bf-746885181278/58647e532fcc3a45209c13cdfbf30c74/dotnet-runtime-3.0.0-linux-arm.tar.gz

创建dotnet解压的目录

sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet

创建环境变量地址软链接

sudo ln -s /opt/dotnet/dotnet /usr/local/bin

在终端中检测 dotnet core环境是否配置完成

dotnet

第三步:

参考官方在win10上创建一个 avalonia 的项目。

  • 安装最新版本的avalon包 ,参考地址
  • 修改Program.cs
  • namespace wf
    {
    class Program
    {
    // Initialization code. Don't use any Avalonia, third-party APIs or any
    // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
    // yet and stuff might break.
    public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);//.Start(AppMain, args); // Avalonia configuration, don't remove; also used by visual designer.
    public static AppBuilder BuildAvaloniaApp()
    => AppBuilder.Configure<App>() .UsePlatformDetect()
    .UseReactiveUI();
    }
    }
  • 修改 App.Xaml.cs
  • namespace wf
    {
    public class App : Application
    {
    public override void Initialize()
    {
    AvaloniaXamlLoader.Load(this);
    } public override void OnFrameworkInitializationCompleted()
    {
    if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
    desktop.MainWindow = new MainWindow()
    {
    DataContext = new MainWindowViewModel(),
    };
    // else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
    // singleView.MainView = new MainView();
    base.OnFrameworkInitializationCompleted();
    }
    }
    }

      

安装作者分钟的在 arm32 linux机器上编译后的skia包

https://www.nuget.org/packages/Avalonia.Skia.Linux.Natives/1.68.0.2
PM> Install-Package Avalonia.Skia.Linux.Natives -Version 1.68.0.2

打开MainWindow.xaml在页面上加几个按钮和文本

  <StackPanel>
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/> <Button Classes="btn" Command="{Binding Go}" Content="click me"></Button>
<ContentControl Content="{Binding SubContent}"></ContentControl>
</StackPanel>

对应的 MainWindowViewModel.cs

namespace wf.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
private object _subContent;
public string Greeting => "Welcome to Avalonia!"; public object SubContent
{
get => _subContent;
set => this.RaiseAndSetIfChanged(ref _subContent, value);
} public void Go()
{
SubContent = new Uc();
} public void Go2()
{
SubContent = new Uc();
}
}
}

 其中 UC是一个自定义的控件,

<UserControl 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="wf.Views.Uc">
<StackPanel>
<TextBlock Text="我是子控件" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Button Content="biubiubiu"></Button>
<Calendar></Calendar>
</StackPanel>
</UserControl>

在window上按F5运行程序,如下图所示

cmd到项目根目录输入如下命令完成 linux下的项目发布

dotnet publish -r linux-arm -f netcoreapp3.0

把 \bin\Debug\netcoreapp3.0\linux-arm 下的 publish 上传到树莓派上,在树莓派终端打开输入如下命令

chmod +x publish/xxx
./xxx

稍等片刻会打开窗体,但是发现窗体上的文字没有被渲染出来,如下所示

经过在作者github上的询问得知 是因为字体问题,我不知道avalonia ui用的什么字体,但是我们可以全局修改它的字体,具体步骤如下:

ssh到树莓派执行如下命令安装微软的字体。这里我们主要使用的是微软雅黑的字体

sudo apt-get install ttf-mscorefonts-installer

打开项目的App.Xam参考下面的代码修改

<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:wf"
x:Class="wf.App">
<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates> <Application.Resources>
<FontFamily x:Key="yh">微软雅黑</FontFamily>
</Application.Resources>
<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<Style Selector="Window">
<Setter Property="FontFamily" Value="{StaticResource yh}"></Setter>
</Style>
</Application.Styles>
</Application>

  

重新编译,发送的树莓派上执行,即可打开窗口,毕业字体也可以渲染出来。

如果字体还是没有渲染出来,建议把windows下的微软雅黑的字体拷贝到linux上安装:

1、到win10下复制字体(C:\Windows\Fonts)
雅黑:msyh 
等等 你要的字体

2、将要的字体复制到 /usr/share/fonts/chinese/TrueType 目录下 (su cp /fonts/* //usr/share/fonts/chinese/TrueType/*)

3、修改字体权限,使root以外的用户可以使用这些字体。

4、建立字体缓存,命令:cd /usr/share/fonts/chinses/TrueType

mkfontscale
mkfontdir 
fc-cache -fv

5、重启,即可使用。

树莓派 Raspberry Pi 4,.net core 3.0 ,Avalonia UI 开发的更多相关文章

  1. 树莓派(Raspberry Pi 3) - 系统烧录及xshell连接

    树莓派(Raspberry pi)是一块集成度极高的ARM开发板,不仅包含了HDMI,RCA,CSI,HDMI,GPIO等端口,还支持蓝牙以及无线通信.由于 Raspberry Pi 几乎是为 Lin ...

  2. 外网登录访问树莓派 Raspberry Pi

    外网登录访问树莓派 Raspberry Pi 本地的树莓派 Raspberry Pi,只能在局域网内访问,怎样从公网也能登录访问树莓派 Raspberry Pi? 本文将介绍具体的实现步骤. 1. 准 ...

  3. 树莓派(Raspberry Pi)使用Shell编写的极简Service

    树莓派(Raspberry Pi)运行的系统是基于Debian的,不仅可以运行Shell,还支持systemd和docker,可以编写一个简单的服务,让其在启动时运行,执行一些自动化的操作.这里在Ra ...

  4. 树莓派(raspberry pi)学习11: 将树莓派变成一个Web服务器(转)

    将树莓派变成一个Web服务器,通过访问网页,就可以控制树莓派,比如:查看摄像头\开灯等等. 一想到Linux Web服务器,我们首先想到的是,Apache + MySql + Php. 树莓派可以安装 ...

  5. VLOG丨树莓派Raspberry Pi 3安装PLEX并挂载USB硬盘打造最牛的微型家庭影音服务器2018

    视频介绍 树莓派3安装目前最流行的PLEX服务器,实现既能最大限度降低功耗,也能随时随地观看分享影片. 一.在树莓派下安装PLEX媒体服务器 1.在终端,将你的树莓派更新至最新 sudo apt up ...

  6. 用树莓派Raspberry Pi和Micro:bit做一个自拍器

    在这个项目中,我们将使用Python来构建一个由Micro:bit触发树莓派Raspberry Pi和相机模块的自拍器.这是开始使用硬件和简单文本编程的好方法. 我们将学习: 如何设置Raspberr ...

  7. 在 树莓派(Raspberry PI) 中使用 Docker 运行 MySQL

    在 树莓派(Raspberry PI) 中使用 Docker 运行 MySQL 本文主要利用 biarms 提供的 Dockerfile 进行安装. 笔者最新发现! MySQL 5.7 Docker ...

  8. 树莓派(Raspberry Pi)搭建简单的lamp服务

    树莓派(Raspberry Pi)搭建简单的lamp服务: 1. LAMP 的安装 sudo apt-get install apache2 mysql-server mysql-client php ...

  9. 树莓派(raspberry pi)学习4: 更改键盘布局(转)

    树莓派(raspberry pi)用了几次后,发现键盘老是按错,一些字符打不出来或打错 这个问题,折腾我半天.还是把心得分享一下吧 上网查,发现是键盘布局不对,树莓派(raspberry pi)是英国 ...

随机推荐

  1. aaa服务器

    验证 授权 记账 authentication\authorization.accounting

  2. 使用powershell的remove

    使用Remove-Module -Name Functions2 只是移除当前会话的模块 并且Import-Module -Name Functions2与 Remove-Module -Name F ...

  3. HDU - 6223 Infinite Fraction Path (倍增+后缀数组)

    题意:给定一个长度为n(n<=150000)的字符串,每个下标i与(i*i+1)%n连边,求从任意下标出发走n步能走出的字典序最大的字符串. 把下标看成结点,由于每个结点有唯一的后继,因此形成的 ...

  4. SpringBoot对接收及返回Instant类型的处理(转)

    一:处理post请求json中的Instant类型1.springboot中日期格式化配置: spring: jackson: date-format: yyyy-MM-dd HH:mm:ss tim ...

  5. 《Learning Structured Representation for Text Classification via Reinforcement Learning》论文翻译.md

    摘要 表征学习是自然语言处理中的一个基本问题.本文研究了如何学习文本分类的结构化表示.与大多数既不使用结构又依赖于预先指定结构的现有表示模型不同,我们提出了一种强化学习(RL)方法,通过自动覆盖优化结 ...

  6. [Javascirpt] What’s new in JavaScript (Google I/O ’19)

    Private variable in class: class Counter { #count = 0; // cannot be access publicly get value () { r ...

  7. confirm 弹出信息

    if(confirm("真的要删除吗?")){ alert("点击了确认按钮"); } else{ alert("点击了取消按钮"); } ...

  8. Git入门学习和使用

    #开篇废话 开篇废话又回来了,离开博客算是有一年了,之间曾经痛下很多次决心,继续写博客,后来都失败了,前年为了申请个CSDN专家,每天发博客,那个高产的状态,现在已然不行了,时过境迁,当时为了吃口饱饭 ...

  9. spring cloud stream整合

    spring cloud stream整体架构核心概念图: 图一:消息的发送端和接收端可以是不同的中间件 图二: 图三:在消息的发送之前和消息的接收端套了一层管道 @Output:输出注释,用于定义发 ...

  10. Java并发编程的艺术笔记(十)——Semaphore详解

    作用:控制同时访问某个特定资源的线程数量,用在流量控制.