TapGestureRecognizer不适用于Span Inside标签(FormattedText).Command没有开火,甚至Tapped也没有开火. 我在用<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>

以下是我的XAML:

<Label LineHeight="1.3" HorizontalTextAlignment="Center">
                <Label.FormattedText>
                    <FormattedString>
                        <Span Text="Read our " />                  
                        <local:HyperlinkSpan Text="Privacy Policy"
                                         Url="https://www.eurycele.com" />
                        
                        <Span Text=". Tap &quot;Agree and continue&quot; to accept the " />
                        
                        <local:HyperlinkSpan Text="Terms of Service"
                                         Url="https://www.eurycele.com" />
                        <Span Text="Terms of Service"
                              TextColor="Blue">
                            <Span.GestureRecognizers>
                                <TapGestureRecognizer Command="{Binding TapCommand}"
                                                      CommandParameter="https://learn.microsoft.com/xamarin/"  />
                            </Span.GestureRecognizers>
                        </Span> 
                        <Span Text="." />
                    </FormattedString>
                </Label.FormattedText>
            </Label>

local:HyperlinkSpan是从https://github.com/xamarin/xamarin-forms-samples/blob/main/UserInterface/Hyperlinks/HyperlinkDemo/HyperlinkSpan.cs减go

我已经try 了以下方法:

请提个建议.

推荐答案

我可以在我这边重现您的问题,这是一个关于Span.GestureRecognizers的已知问题,它不适用于毛伊岛.NET中Label内部的Span

你可以在这里关注它:https://github.com/dotnet/maui/issues/4734.

作为替代解决方法,您可以使用Label.GestureRecognizers而不是Span.GestureRecognizers,如下所示:

<Label Text="Terms of Service" 
       TextColor="Blue" 
       LineHeight="1.3" 
       HorizontalTextAlignment="Center"> 
       
      <Label.GestureRecognizers>
               <TapGestureRecognizer Command="{Binding TapCommand}"                                     CommandParameter="https://learn.microsoft.com/xamarin/"  />
       </Label.GestureRecognizers>
</Label>

最新情况:

这是由于.NET Maui中的一个潜在问题,请参见dotnet/maui#8004.AFAIK,它将针对.NET 8版本进行修复.

Csharp相关问答推荐

如何在Shell中创建WinUI 3图形界面?

如何将两个查询结果组合在C#ASP.NET MHC控制器中

如何打印已添加到List的Linq值,而不是C#中的:System.Collections.Generic.List ' 1[System.Int32]?

Serilog SQL服务器接收器使用UTC作为时间戳

处理. netstandard2.0项目中HttpClient.SslProtocol的PlatformNotSupportedException问题""

. NET 8使用COM向VB6公开

在. net毛伊岛窗口的深度链接已经创建""

使用LINQ to XML获取元素值列表是不起作用的

为什么总输出就像12.3没有一分一样?

Blazor EventCallback<;MyType<;T>;>;

Rider将.NET安装在哪里

如何在页面重新加载后保持菜单切换状态

有空容错运算符的对立面吗?

如何将端点(或с匹配请求并判断其路径)添加到BCL?

当我没有此令牌时,为什么语法报告EOF错误?

具有可空类型的C#NOTNULL约束具有意外行为

泛型参数在.NET 8 AOT中没有匹配的批注

我的命名管道在第一次连接后工作正常,但后来我得到了System.ObjectDisposedException:无法访问关闭的管道

将C#类导入到PowerShell

无效的Zip文件-Zip存档