.Net-Avalonia学习笔记(二)-HelloWorld与简易登录页
一、HelloWorld
1、创建解决方案
2、试运行
3、修改代码
修改MainView.axaml文件,将“Welcome to Avalonia!”改为“HelloWorld!”;
4、结果
二、创建登录窗体
1、SignInWindow.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="600" d:DesignHeight="450" Width="600" Height="450"
x:Class="AvaloniaUI_Simple.SignInWindow"
Title="登录窗体">
<Grid>
<StackPanel Orientation="Vertical">
<Panel Height="60"/>
<Label Content="欢迎登录" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Panel Height="40"/>
<StackPanel Width="290" Orientation="Horizontal" HorizontalAlignment="Center">
<Label Content="账户:" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="18"/>
<TextBox Name="txtName" Width="224" FontSize="20"/>
</StackPanel>
<Panel Height="12"/>
<StackPanel Width="290" Orientation="Horizontal" HorizontalAlignment="Center">
<Label Content="密码:" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="18"/>
<TextBox Name="txtPwd" Width="224" FontSize="20"/>
</StackPanel>
<Panel Height="20"/>
<!-- Orientation="Horizontal"-->
<Button Content="登录" Name="Btn_SignIn" FontSize="20" Foreground="White" Width="282" Height="48" Background="#375778" HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Cursor="Hand" />
<Panel Height="10"/>
<Button Content="注册" Name="Btn_Register" FontSize="20" Foreground="White" Width="282" Height="48" Background="#375778" HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
</StackPanel>
</Grid>
</Window>
2、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="800" d:DesignHeight="450" Width="800" Height="450"
x:Class="AvaloniaUI_Simple.MainWindow"
Title="AvaloniaUI_Simple -Bili执笔小白">
<Grid>
<StackPanel Margin="15">
<Label Content="HelloWorld!"/>
<Panel Height="10" />
<Button Content="登录" Width="74" Name="Btn_SignIn" HorizontalContentAlignment="Center" Click="BtnSignIn_Click"/>
</StackPanel>
</Grid>
</Window>
3、MainWindow.axaml.cs
using Avalonia.Controls;
using Avalonia.Interactivity;
using System.Diagnostics;
namespace AvaloniaUI_Simple
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
/// <summary>
/// 打开 登录页
/// </summary>
/// <param name="source"></param>
/// <param name="args"></param>
public void BtnSignIn_Click(object source, RoutedEventArgs args)
{
SignInWindow signInWindow = new SignInWindow();
signInWindow.Show();
}
}
}
本文来自博客园,作者:꧁执笔小白꧂,转载请注明原文链接:https://www.cnblogs.com/qq2806933146xiaobai/p/18320499