我的XAML:
<ScrollViewer Name="MyScrollViewer" CanContentScroll="True">
<Grid Grid.Column="1" Margin="10">
MouseWheel="Grid_OnMouseWheel">
<Grid.RenderTransform>
<ScaleTransform ScaleY="-1" />
</Grid.RenderTransform>
...
</Grid>
</ScrollViewer>
我的代码:
如您所见,我需要左下角的零Y坐标角:
private void Grid_OnMouseWheel(object sender, MouseWheelEventArgs e)
{
UIElement element = (UIElement)sender;
Point position = e.GetPosition(element);
double Width = element.RenderSize.Width;
double Height = element.RenderSize.Height;
Matrix GridMatrix = GUIGrid.LayoutTransform.Value;
if (e.Delta > 0)
{
ScaleFactor += 1;
ScaleTransform Transform = new ScaleTransform(ScaleFactor, ScaleFactor, position.X, position.Y);
Transform.ScaleY = -ScaleFactor;
GUIGrid.RenderTransform = Transform;
}
else
{
ScaleFactor -= 1;
if (ScaleFactor <= 0)
ScaleFactor = 1;
ScaleTransform Transform = new ScaleTransform(ScaleFactor, ScaleFactor, position.X, position.Y);
Transform.ScaleY = -ScaleFactor;
GUIGrid.RenderTransform = Transform;
}
e.Handled = true;
}
我的问题:
我没有得到正确的坐标,我的缩放飞离屏幕。我已经尝试将-Y设置为位置,但这还不够。如果有人可以解释为什么这不符合我的预期呢?
答案 0 :(得分:-1)
嗯,没有像我希望的那样简单,文档很差!
ScaleTransform Transform = new ScaleTransform();
Transform.Value.ScaleAtPrepend(ScaleFactor, ScaleFactor, Position.X, Position.Y);
Transform.ScaleX = ScaleFactor;
Transform.ScaleY = -ScaleFactor;
GUIGrid.RenderTransform = Transform;
现在按照我的预期工作。