How to handle Pinch in & out in UWP applications

I have TextBlockin my application. I want to process pinch in & outto change the font size. when the event fires ManipulationDelta, I check the property Scale, but most often it Scaleis 1, even my fingers are far away or close. or it doesn’t work as I expected.

Can someone show me an example of how to find what happened or happened?

+4
source share
3 answers

Put a scrollviewer around it. It scales using a pinch out of the box.

0
source

Have you installed ManipulationModeon TextBlockto Scale?

, Grid Border Transparent . TextBlock , , .

<Grid ManipulationMode="Scale" ManipulationDelta="YourHandler">
   <TextBlock Text="YourTextBlock" />
</Grid>
0

I'm not sure if there are any problems in your code, but I made a simple code example. He can achieve your goal.

Please check the following code:

<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;
}
0
source

Source: https://habr.com/ru/post/1665447/


All Articles