Closed CostasAthan closed 1 month ago
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
This issue has been verified using Visual Studio 17.12 Preview 1 (8.0.80 & 8.0.3). Can repro on android platform with sample project.
I cannot reproduce it
https://github.com/user-attachments/assets/4a88166e-901d-4de2-b624-f07f4fe91980
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
BindingContext = new MainPageViewModel();
}
}
public class MainPageViewModel : INotifyPropertyChanged
{
public MainPageViewModel()
{
OpenAlertCommand = new Command(()=>{
Application.Current!.MainPage.DisplayAlert("sad","asd","sda");
});
}
public Command OpenAlertCommand{get; set;}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
@kubaflo
Is your version of code necessary? Shouldn't my version work too? It used to work with Xamarin.Forms.
@CostasAthan Yeah, you're incorrectly using Community Toolkit Rely Command: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/generators/relaycommand
@CostasAthan, the problem is with the relay command's name. When using the RelayCommand attribute, the command is generated by appending Command to the method name. So, in XAML, we need to use the method name with Command appended. If you update your relay command as shown below, it should work correctly.
[RelayCommand]
private async Task OpenWithRelay(string url)`
{
await Launcher.OpenAsync(url);
}
<Span.GestureRecognizers>
<TapGestureRecognizer Command="{Binding OpenWithRelayCommand}" CommandParameter="https://example.com/" />
</Span.GestureRecognizers>
@CostasAthan @karthikraja-arumugam is right! Let us know if it fixes your problem :)
@karthikraja-arumugam
It's not only the RelayCommand
that does not work though. In my version of code neither ICommand
nor Command
work. ICommand
definitely used to work in Xamarin.Forms implemented in the same way I have implemented it in the repository I have shared for this issue.
@kubaflo
Your ViewModel
approach works fine. But the ICommand
in Xamarin.Forms definitely used to work also in the way I have implemented my code. I don't know if that's a bug or if something has changed with MAUI.
Description
This is a problem supposedly solved and closed: https://github.com/dotnet/maui/pull/14410, but unfortunately in reality it still exists.
With .NET 8 and targeting Android 34 the gestures still don't work on
Span
tags ofLabels
.I have provided a link to a repository that reproduces the bug.
Steps to Reproduce
No response
Link to public reproduction project repository
https://github.com/CostasAthan/GesturesLabelSpansFailure
Version with bug
Unknown/Other
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 34
Did you find any workaround?
No.
Relevant log output
No response