跳到主要内容

设计预览

在这个页面上,您将探索窗口的属性,然后使用其中一些属性来调整窗口在预览窗格中显示时的大小。

检查XAML的 <Window> 标签。它看起来像这样:

<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:GetStartedApp.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="450"
x:Class="GetStartedApp.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="GetStartedApp">

Window (窗口)标签首先定义了 Avalonia 使用的一些 XML 命名空间。并为其指定了别名'x'、'd' 和 d'mc'。

设计命名空间 'd' 允许设置设计时属性 d:DesignWidthd:DesignHeight。 在上面的代码示例中的设置,可以使预览窗格看起来更像是纵向的移动设备。

<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:GetStartedApp.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="450"
x:Class="GetStartedApp.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="GetStartedApp">

设置了这些属性后,窗口的预览现在看起来像这样:

Application runningApplication running

在下一页中,您将看到如何通过响应按钮点击事件为应用程序添加一些动作。