我的应用中有JOIN
。我想在其上处理TextBlock
以调整其字体大小。当pinch in & out
事件触发时,我会检查ManipulationDelta
属性,但大多数时候Scale
是1,即使我的手指远离或越来越近。
或者它没有像我预期的那样工作。
任何人都可以告诉我一个如何找到捏进或出发的例子吗?
答案 0 :(得分:0)
在它周围放一个滚动查看器。它通过开箱即可进行缩放。
答案 1 :(得分:0)
您是否已将ManipulationMode
上的TextBlock
设置为Scale
?
另外,我建议您将操作放在Grid
或Border
容器上,背景为Transparent
以捕获操作事件。在TextBlock
的情况下,您可能遇到可能导致操作事件未被触发的命中测试问题。
<Grid ManipulationMode="Scale" ManipulationDelta="YourHandler">
<TextBlock Text="YourTextBlock" />
</Grid>
答案 2 :(得分:0)
我不确定您的代码中是否存在某些问题,但我已经编写了一个简单的代码示例。它可以实现你的目标。
请检查以下代码:
<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;
}