【发布时间】:2020-03-30 10:16:05
【问题描述】:
我有一个问题,我不知道如何解决。我有一个 UWP 应用程序。在 XAML 中有一个具有 RenderTransformOrigin 的网格。但是当我改变网格的宽度时,我会给它什么值并不重要,宽度是从中心计算出来的。
这是 XAML
<Page
x:Class="TestApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Background="White">
<Grid Background="Red" x:Name="image" RenderTransformOrigin="0,0">
<Grid.RenderTransform>
<CompositeTransform />
</Grid.RenderTransform>
<Border x:Name="LeftScale" Width="50" Height="50" Background="Black" HorizontalAlignment="Left" VerticalAlignment="Center" ManipulationDelta="LeftScale_ManipulationDelta" ManipulationMode="TranslateX,TranslateY" />
</Grid>
</Grid>
还有 C#
public sealed partial class MainPage : Page
{
public Point Origin { get; set; }
public MainPage()
{
this.InitializeComponent();
image.Width = 500;
image.Height = 500;
}
private void LeftScale_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
Origin = new Point(1, 0.5);
image.RenderTransformOrigin = Origin;
image.Width -= e.Delta.Translation.X;
}
}
感谢关注。
【问题讨论】:
标签: c# .net .net-core uwp uwp-xaml