欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > vscode开发avalonia

vscode开发avalonia

2024/10/26 8:13:22 来源:https://blog.csdn.net/qq_36437991/article/details/140896213  浏览:    关键词:vscode开发avalonia

安装

安装.net 8
安装avalonia模板

dotnet new install Avalonia.Templates

在这里插入图片描述

创建项目

dotnet new avalonia.app -o GetStartedApp

安装c# dev kit插件和Avalonia for VSCode Community
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
dotnet run运行
在这里插入图片描述

修改代码

MainWindow.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="200" d:DesignHeight="450"x:Class="GetStartedApp.MainWindow"Title="GetStartedApp"><TextBlock Text="My Text" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Window>

在这里插入图片描述
继续修改代码

<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="200" d:DesignHeight="450"x:Class="GetStartedApp.MainWindow"Title="GetStartedApp"><Button HorizontalAlignment="Center">Calculate</Button>
</Window>

在这里插入图片描述
增加布局

<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="200" d:DesignHeight="450"x:Class="GetStartedApp.MainWindow"Title="GetStartedApp"><StackPanel><Border Margin="5" CornerRadius="10"Background="LightBlue"><TextBlock Margin="5"FontSize="24" HorizontalAlignment="Center"Text="温度转换器"></TextBlock></Border><Grid ShowGridLines="True"  Margin="5" ColumnDefinitions="120, 100" RowDefinitions="Auto, Auto, Auto"><Label Grid.Row="0" Grid.Column="0" Margin="10">Celsius</Label><TextBox Name="celsius" Grid.Row="0" Grid.Column="1" Margin="0 5" Text="0"/><Label Grid.Row="1" Grid.Column="0" Margin="10">Fahrenheit</Label><TextBox Name="fahrenheit" Grid.Row="1"  Grid.Column="1" Margin="0 5" Text="0"/><Button Grid.Row="2" Grid.Column="1" Margin="0 5" Click="ButtonClicked">Calculate</Button></Grid>  </StackPanel>
</Window>

在这里插入图片描述
绑定点击事件,修改MainWindow.axaml.cs

public void ButtonClicked(object source, RoutedEventArgs args)
{Debug.WriteLine("Click!");Debug.WriteLine($"Click! Celsius={celsius.Text}");if (double.TryParse(celsius.Text, out double C)){var F = C * (9d / 5d) + 32;fahrenheit.Text = F.ToString("0.0");}else{celsius.Text = "0";fahrenheit.Text = "0";}
}

参考

https://docs.avaloniaui.net/zh-Hans/docs/welcome

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com