为什么单击标签时将焦点更改为条目? Xamarin.Forms/UWP

Why changes the focus to the entry when I click the label? Xamarin.Forms/UWP

我有一个问题,我做了一个例子来说明。

这段代码建立两对label/entry。如果我将焦点设置到第二个条目并单击第二个标签,焦点将转到第一个条目 (!?)...

我需要ScrollView,因为在真实的应用中,有很多视图需要滚动。

我在 Win10/11 PC 上的 UWP 项目中试过这个。

如何避免这种奇怪的行为?

<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="TestForm.MainPage">
    
    <ScrollView x:Name="scroll">
        <StackLayout>

            <Label Text="Title01"/>
            <Entry/>

            <Label Text="Title02"/>
            <Entry/>

        </StackLayout>
    </ScrollView>

</ContentPage>

作为一种解决方法,您可以在 stacklayout 上添加 TapGestureRecognizer 以在第一个条目上设置 unfous,例如:

<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="TestForm.MainPage">
    <StackLayout>

 <StackLayout.GestureRecognizers>
        <TapGestureRecognizer
           Tapped="OnTapGestureRecognizerTapped"/>
    </StackLayout.GestureRecognizers>
    <ScrollView x:Name="scroll">
        <StackLayout>
      <Button HeightRequest="0" WidthRequest="1" />//add button
            <Label Text="Title01"/>
            <Entry x:Name="entry1"/>

            <Label Text="Title02"/>
            <Entry/>

        </StackLayout>
    </ScrollView>
  </StackLayout>

</ContentPage>

后面的代码:

void OnTapGestureRecognizerTapped(object sender, EventArgs args)
{
 if(!entry1.isFocused)
  {entry1.Unfocus(); }
  
}

这是 UWP 中的错误。请参阅下面的参考资料。我希望这将在 netMaui 中得到解决...

[Bug] Erroneous behavior: Why changes the focus to the entry when I click the label? Xamarin.Forms/UWP #15180

ScrollView Jumps when Non-Interactable Element is Clicked #5652

ScrollViewer Jumps to Top-most TextBox (UWP app) #597