添加命令行参数,自定义扩展已经更新。

https://www.cnblogs.com/dalgleish/p/18972924

image

LoadFromCommandLine.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"
        Height="300" Width="300"
        x:Class="AvaloniaUI.LoadFromCommandLine"
        Title="LoadFromCommandLine">
    <Grid RowDefinitions="*,auto">
        <TextBlock Name="Output"/>
        <Button Grid.Row="1" Click="LoadFile">加载命令行参数</Button>
    </Grid>
</Window>

LoadFromCommandLine.axaml.cs代码

using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
using Shares.Avalonia;
using System;

namespace AvaloniaUI;

public partial class LoadFromCommandLine : Window
{
    public LoadFromCommandLine()
    {
        InitializeComponent();
    }

    private async void LoadFile(object? sender, RoutedEventArgs e)
    {
        Output.Text = await this.ReadAllTextAsync(this.GetCommandLine()![0]);
    }
}

运行效果

image

 

posted on 2025-07-30 13:22  dalgleish  阅读(12)  评论(0)    收藏  举报