我无法在raspbian lite上运行avalonia应用程序。我使用树莓3b +和树莓lite操作系统。我使用这个教程:
https://docs.avaloniaui.net/guides/deep-dives/running-on-raspbian-lite-via-drm
对不起,但是我得到这个错误:
AXN0002 - XamlX.XamlParseException: Unable to resolve type MainView from namespace clr-namespace:AvaloniaRaspbianLiteDrm row 10, position 4
我的主窗口是这样的:
<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"
xmlns:avaloniaRaspbianLiteDrm="clr-namespace:AvaloniaRaspbianLiteDrm"
mc:Ignorable="d"
d:DesignWidth="800"
d:DesignHeight="450"
x:Class="AvaloniaRaspbianLiteDrm.Views.MainWindow"
Title="AvaloniaRaspbianLiteDrm">
<avaloniaRaspbianLiteDrm:MainView/>
</Window>
MainSingleView:
<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"
xmlns:avaloniaRaspbianLiteDrm="clr-namespace:AvaloniaRaspbianLiteDrm"
mc:Ignorable="d"
d:DesignWidth="800"
d:DesignHeight="450"
x:Class="AvaloniaRaspbianLiteDrm.Views.MainSingleView">
<avaloniaRaspbianLiteDrm:MainView/>
</UserControl>
MainView:
<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="AvaloniaRaspbianLiteDrm.Views.MainView">
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="30"
Spacing="30">
<TextBlock FontSize="25">
Welcome to Avalonia! The best XAML framework ever ♥
</TextBlock>
<Slider />
</StackPanel>
</UserControl>
Program.cs:
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;
using System;
using System.Linq;
using System.Threading;
namespace AvaloniaRaspbianLiteDrm
{
internal 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.
[STAThread]
public static int Main(string[] args)
{
var builder = BuildAvaloniaApp();
if (args.Contains("--drm"))
{
SilenceConsole();
return builder.StartLinuxDrm(args);
}
return builder.StartWithClassicDesktopLifetime(args);
}
private static void SilenceConsole()
{
new Thread(() =>
{
Console.CursorVisible = false;
while (true)
Console.ReadKey(true);
})
{ IsBackground = true }.Start();
}
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
}
}
App.xaml.cs:
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using AvaloniaRaspbianLiteDrm.ViewModels;
using AvaloniaRaspbianLiteDrm.Views;
namespace AvaloniaRaspbianLiteDrm
{
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
desktop.MainWindow = new MainWindow();
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
singleView.MainView = new MainSingleView();
base.OnFrameworkInitializationCompleted();
}
}
}
MainView
在avaloniaRaspbianLiteDrm
命名空间中找不到
正如我在您的示例中看到的,MainView
(如x:Class="AvaloniaRaspbianLiteDrm.Views.MainView
所示)位于AvaloniaRaspbianLiteDrm.Views
名称空间内。您可能忘记了有一个Views
名称空间。
你可能应该改变
xmlns:avaloniaRaspbianLiteDrm="clr-namespace:AvaloniaRaspbianLiteDrm"
xmlns:avaloniaRaspbianLiteDrm="clr-namespace:AvaloniaRaspbianLiteDrm.Views"
确保代码隐藏文件MainView.xaml.cs也使用AvaloniaRaspbianLiteDrm.Views
命名空间。