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



我有一个问题,我做了一个例子来展示它。

此代码建立两对标签/条目。如果我将焦点设置为第二个条目,然后单击第二个标签,焦点将转到第一个条目(!?(。。。

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

我在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中的一个错误。请参阅以下参考资料。我希望这个问题能在茂宜岛得到解决。。。

[错误]错误行为:为什么当我点击标签时会将焦点更改为条目?Xamarin。表格/UWP#15180

点击不可交互元素时滚动视图跳转#5652

ScrollViewer跳转到最顶端的文本框(UWP应用程序(#597

最新更新