您可尝试在您的Render TransformOrigin 集邮器上使用一个转机。
兑换商将接受控制作为参数,并检查其母体内的控制位置是否在0到2之间(ControlHels / 2),如果是计算和返还不同的Render TransformOrigin值。 否则,只是退回违约(0.5,0.5)
Edit:
To answer your comment, I m not sure of the exact syntax since I m not testing this, but I was thinking something similar to the following:
创建您的转换者。 可能必须成为多巴inding转换器
public class RenderTransformConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
// Get parameters - You ll probably want to include validation and default values
UIElement control = (UIElement)value[0];
UIElement parent = (UIElement)value[1];
int controlHeight = control.Height;
int controlXPositionInParent = control.TranslatePoint(new Point(0, 0), parent).X;
if (controlXPositionInParent < (controlHeight * .5))
{
// Calculate a new render transform.
// Should verify I m doing the math right, didn t get much sleep last night
return new Point(0.5, controlXPositionInParent / controlHeight);
}
else
{
return new Point(0.5, 0.5);
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
您的XAML将包括一条线,把改名空间包括在内,并为新皈依者制造一个物体。
<localNamespace:RenderTransformConverter x:Key="renderTransformConverter />
嗣后: 类似情况是:
<Setter Property="RenderTransformOrigin">
<Setter.Value>
<MultiBinding Converter="{StaticResource renderTransformConverter}">
<Binding Path="{Binding RelativeSource=Self}" />
<Binding Path="{Binding RelativeSource=Self, Path=Parent}" />
</MultiBinding>
</Setter.Value>
如果你能够把控制作为变压器的参数,那么我不会感到乐观,但如果你可能不得不重新安排参数,以获得计算所需的任何数值。