Viewbox可以让图形随着窗口变化而变化。
ViewboxResize.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="247" Width="315" x:Class="AvaloniaUI.ViewboxResize" Title="ViewboxResize"> <Grid Margin="5" RowDefinitions="auto,*"> <TextBlock>The first row of a grid.</TextBlock> <Viewbox Grid.Row="1" HorizontalAlignment="Left" MaxHeight="500"> <Canvas Width="200" Height="150"> <Ellipse Fill="Yellow" Stroke="Blue" StrokeThickness="1" Canvas.Left="10" Canvas.Top="50" Width="100" Height="50" HorizontalAlignment="Left"></Ellipse> <Rectangle Fill="Yellow" Stroke="Blue" StrokeThickness="1" Canvas.Left="30" Canvas.Top="40" Width="100" Height="50" HorizontalAlignment="Left"></Rectangle> </Canvas> </Viewbox> </Grid> </Window>
ViewboxResize.axaml.cs代码
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace AvaloniaUI;
public partial class ViewboxResize : Window
{
public ViewboxResize()
{
InitializeComponent();
}
}
运行效果

浙公网安备 33010602011771号