我在我的应用中有一个文本块。我想处理对它的捏合操作,以调整其字体大小。当事件触发时,我检查属性,但大多数情况下,即使我的手指远离或靠近,也是1。或者它不像我预期的那样工作。
有人可以给我展示一个例子,如何找到捏合操作发生了吗?
有人可以给我展示一个例子,如何找到捏合操作发生了吗?
TextBlock
的 ManipulationMode
设置为 Scale
?Grid
或 Border
容器上以捕获操作事件。在 TextBlock
的情况下,您可能会遇到命中测试问题,这可能导致操作事件无法触发。<Grid ManipulationMode="Scale" ManipulationDelta="YourHandler">
<TextBlock Text="YourTextBlock" />
</Grid>
我不确定你的代码是否存在问题,但我已经制作了一个简单的代码示例。它可以实现你的目标。
请检查以下代码:
<Grid Background="Red" Height="200" ManipulationDelta="StackPanel_ManipulationDelta" ManipulationMode="Scale">
<TextBlock FontFamily="Verdana"
FontSize="32"
FontWeight="Bold"
Foreground="SteelBlue"
Text="Scaled Text" IsTextScaleFactorEnabled="True">
<TextBlock.RenderTransform>
<ScaleTransform x:Name="ScaleTransform" ScaleX="1.0" ScaleY="1.0" />
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
private void Grid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
ScaleTransform.ScaleX *= e.Delta.Scale;
ScaleTransform.ScaleY *= e.Delta.Scale;
}