Maui pinch recogniser not working
Haviv Elbsz
2,091
Reputation points
Hi All
why this pinch gesture not work
I am trying to change font size
according to pinch event e.Scale
thanks for any help
<ScrollView.GestureRecognizers>
<PinchGestureRecognizer PinchUpdated="OnPinchUpdated" />
</ScrollView.GestureRecognizers>
namespace MyFilePickerApp
{
public partial class MainPage : ContentPage
{
string AppDataDirectoryPath = "";
int nnFontSize = 16;
double currentScale = 1;
int currentFont = 16;
public MainPage()
{
InitializeComponent();
}
//-----------------------------------------------------------------------------
void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
{
// Handle the pinch
if(e.Scale > currentScale)
{
currentScale = e.Scale;
currentFont += 1;
OpenFileLabel.FontSize = currentFont;
}
else if(e.Scale < currentScale)
{
currentScale = e.Scale;
currentFont -= 1;
OpenFileLabel.FontSize = currentFont;
}
}
//-----------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyFilePickerApp.MainPage"
xmlns:mct="clr-namespace:CommunityToolkit.Maui.Behaviors;assembly=CommunityToolkit.Maui"
FlowDirection="LeftToRight" BackgroundColor="#107e71" >
<Page.Behaviors>
<mct:StatusBarBehavior StatusBarColor="#107e71" StatusBarStyle="LightContent" />
</Page.Behaviors>
<Grid RowDefinitions="10,50,50,*,50,10" ColumnDefinitions="*"
BackgroundColor="#ECE5DD" Margin="10" >
<Label x:Name="SaveFileLabel" FlowDirection="LeftToRight" Grid.Row="1" Grid.Column="0"
Text="Save My File"
FontSize="18"
HorizontalOptions="Center" />
<Grid Grid.Row="2" ColumnDefinitions="2*, 4*, 4* ,4* ,2*" Padding="0,10" >
<Button x:Name="SaveFileBtn" Text="Save a File" BackgroundColor="BlueViolet"
HorizontalOptions="Fill" VerticalOptions="Center"
CornerRadius="20" BorderColor="Black" TextColor="White"
BorderWidth="1"
Clicked="OnSaveFileClicked" FontAttributes="Bold"
Padding="0,0,0,0" Grid.Column="1" />
<Button x:Name="OpenFileBtn" Text="Pick a File" BackgroundColor="BlueViolet"
HorizontalOptions="Fill" VerticalOptions="Center"
CornerRadius="20" BorderColor="Black" TextColor="White"
BorderWidth="1"
Clicked="OnOpenFileClicked" FontAttributes="Bold"
Padding="0,0,0,0" Grid.Column="3" />
</Grid>
<ScrollView x:Name="scroll" Orientation="Vertical" Grid.Row="3" Grid.Column="0"
VerticalScrollBarVisibility="Always" >
<ScrollView.GestureRecognizers>
<PinchGestureRecognizer PinchUpdated="OnPinchUpdated" />
</ScrollView.GestureRecognizers>
<ScrollView Orientation="Horizontal" HorizontalScrollBarVisibility="Always" >
<Label x:Name="OpenFileLabel" FlowDirection="LeftToRight"
Text="Open By File Picker"
FontSize="16"
HorizontalOptions="Start" >
</Label>
</ScrollView>
</ScrollView>
<Grid Grid.Row="4" ColumnDefinitions="2*, 4*, 4* ,4* ,2*" Padding="0,10" >
<Button x:Name="PreviousSize" Text="Size -" BackgroundColor="BlueViolet"
HorizontalOptions="Fill" VerticalOptions="Center"
CornerRadius="20" BorderColor="Black" TextColor="White"
BorderWidth="1"
Clicked="PreviousSize_Clicked" FontAttributes="Bold"
Padding="0,0,0,0" Grid.Column="1" />
<Label x:Name="fontSize" Text="Font 16" FontAttributes="Bold"
HorizontalOptions="Center" VerticalOptions="Center"
Grid.Column="2" />
<Button x:Name="NextSize" Text="Size +" BackgroundColor="BlueViolet"
HorizontalOptions="Fill" VerticalOptions="Center"
CornerRadius="20" BorderColor="Black" TextColor="White"
BorderWidth="1"
Clicked="NextSize_Clicked" FontAttributes="Bold"
Padding="0,0,0,0" Grid.Column="3" />
</Grid>
</Grid>
</ContentPage>
Developer technologies | .NET | .NET MAUI
4,171 questions
Sign in to answer