我想将 scaleTransform 绑定到传递ActualWidth
or的转换器ActualHeight
。
这是我想做的:
<Canvas x:Name="Canevas">
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform
ScaleX="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UIElement}},
Path=ActualWidth, Mode=OneWay,
Converter={StaticResource ScaleConverter},
ConverterParameter={Binding Path=ActualWidth}"
ScaleY="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UIElement}},
Path=ActualHeight, Mode=OneWay,
Converter={StaticResource ScaleConverter},
ConverterParameter={Binding Path=ActualHeight}}"
/>
</TransformGroup>
</Canvas.RenderTransform>
<Ellipse Canvas.Left="47" Canvas.Top="48" Height="155"
Name="ellipse1" Stroke="Black" Width="174" Fill="#FF00C6C3" />
问题是这不编译:
ConverterParameter={Binding Path=ActualHeight}
所以我想知道如何将这些属性作为我的转换器的参数移动?是否可以在完整的 Xaml 中解决?
非常感谢您的帮助 !
转换器源代码:
public class ScaleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
double v = (double)value;
var actualSize = (double)parameter; //ActualWidth, ActualHeight
var vScale = v * (1 + (v / actualSize));
return vScale;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}