控件内容
您可能已经看到了在将按钮控件放入_Avalonia UI_窗口的内容区域时会发生什么。
信息
关于_Avalonia UI_控件区域的概念,可以在此处找到讨论。
例如:
<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"
x:Class="MySample.MainWindow"
Title="MySample">
<Button HorizontalAlignment="Center" >Hello World!</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="800" d:DesignHeight="450"
x:Class="MySample.MainWindow"
Title="MySample">
Hello World!
</Window>
窗口将显示该字符串:
但是如果您尝试显示在窗口中定义的类的对象会发生什么呢?
例如,使用上面的Student
类定义:
namespace MySample
{
public class Student
{
public string FirstName { get; set;} = String.Empty;
public string LastName { get; set;} = String.Empty;
}
}
并且将XML命名空间local