需要帮助才能理解为什么我的代码不起作用 仅限XAML(无代码)
<Window x:Class="Chapter02.ScaleInCustomSystem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Scale In Custom System" Height="310" Width="260">
<StackPanel Height="280" Width="250">
<Border BorderBrush="Black" BorderThickness="1" Height="200" Width="200" Margin="20">
<Canvas Height="200" Width="200">
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="-1"/>
<TranslateTransform Y="200"/>
</TransformGroup>
</Canvas.RenderTransform>
<Line X1="0" Y1="0" X2="80" Y2="80" Stroke="Black" StrokeThickness="2">
<Line.RenderTransform>
<ScaleTransform ScaleX="{Binding ElementName=slider, Path=Value}"
ScaleY="{Binding ElementName=slider, Path=value}"/>
</Line.RenderTransform>
</Line>
<Rectangle Canvas.Top="100" Canvas.Left="30" Width="80" Height="40" Stroke="DarkRed" StrokeThickness="3">
<Rectangle.RenderTransform>
<ScaleTransform ScaleX="{Binding ElementName=slider, Path=Value}"
ScaleY="{Binding ElementName=slider, Path=value}"/>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
</Border>
<Slider Name="slider" Minimum="0" Maximum="3" Value="1" TickPlacement="BottomRight" TickFrequency="0.2" IsSnapToTickEnabled="True"/>
</StackPanel>
</Window>
当我运行此代码时,滑块仅缩放x轴上的图像,而y轴不执行任何操作,当我仅使用ScaleY参数运行代码时,它什么都不做。 我做错了什么?
编辑:为了澄清,我从一本我正在阅读的书中学习了这个代码来学习WPF。书名是“实用WPF图形编程”。
答案 0 :(得分:1)
将value
替换为Value
。这是区分大小写的
ScaleY="{Binding ElementName=slider, Path=Value}"/>