解决Canvas无法缩放,配合Viewbox限定Canvas大小来完成缩放

This commit is contained in:
YONGYE 2025-10-10 16:34:35 +08:00
parent e9d9e67851
commit ec3c068817

View File

@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignWidth="200" Height="482"> mc:Ignorable="d" d:DesignWidth="200" >
<Border Background="White" BorderBrush="#CCCCCC" BorderThickness="1"> <Border Background="White" BorderBrush="#CCCCCC" BorderThickness="1">
<Grid Margin="0,0,0,-1"> <Grid Margin="0,0,0,-1">
<Grid.RowDefinitions> <Grid.RowDefinitions>
@ -20,7 +20,9 @@
Background="{Binding HeaderBackground, RelativeSource={RelativeSource AncestorType=UserControl}}"/> Background="{Binding HeaderBackground, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
<!-- 图表区域 --> <!-- 图表区域 -->
<Canvas Grid.Row="1" Background="White" Margin="20,20,20,3" Name="ChartCanvas"> <Viewbox Grid.Row="1" Stretch="Uniform">
<Canvas Width="160" Height="440" Grid.Row="1" Background="White" Margin="20,20,20,3" Name="ChartCanvas">
<!-- 柱状图容器边框 - 左边界线 --> <!-- 柱状图容器边框 - 左边界线 -->
<Line X1="40" Y1="20" X2="40" Y2="420" Stroke="Black" StrokeThickness="1"/> <Line X1="40" Y1="20" X2="40" Y2="420" Stroke="Black" StrokeThickness="1"/>
<!-- 右边界线 --> <!-- 右边界线 -->
@ -209,6 +211,7 @@
</ItemsControl.ItemContainerStyle> </ItemsControl.ItemContainerStyle>
</ItemsControl> </ItemsControl>
</Canvas> </Canvas>
</Viewbox>
</Grid> </Grid>
</Border> </Border>
</UserControl> </UserControl>