gpt4 book ai didi

.net MAUI - Hide keyboard when SearchBar lost focus(.net MAUI -当SearchBar失去焦点时隐藏键盘)

转载 作者:bug小助手 更新时间:2023-10-24 19:52:11 30 4
gpt4 key购买 nike



Here is a ContentPage with a SearchBar and a ListView.
ListView is updating as the user type in the SearchBar.

这是一个带有搜索栏和ListView的内容页面。当用户在搜索栏中键入内容时,ListView正在更新。


<StackLayout>
<SearchBar Placeholder="Rechercher..." TextChanged="..." x:Name="searchBar"/>
<ListView ItemTapped="..." HasUnevenRows="True" SelectionMode="None" x:Name="ListView_Abonnes"
ItemsSource="..." ItemTemplate="..." Refreshing="..." IsPullToRefreshEnabled="True">
</StackLayout>

The problem is that when the user scoll the ListView results, the keyboard does not close automatically.
Please, somebody know how to do if we want that the keyboard close when user scoll the ListView ?

问题是,当用户阅读ListView结果时,键盘不会自动关闭。请问,谁知道怎么做,如果我们希望键盘关闭时,用户scoll列表视图?


Thanks you

谢谢你


I already try to catch gesture recognizer on the StackLayout, and I also try to catch the scrolled event on the ListView, but that has no effect because the ListView scrolled() event is called when updated.

我已经尝试在StackLayout上捕获手势识别器,并且还尝试在ListView上捕获Scrobled事件,但这没有任何效果,因为ListView Scrored()事件在更新时被调用。


更多回答
优秀答案推荐

You can call the Scrolled event and then hide the Soft Input Keyboard if it is currently visible using Maui Community toolkit.

您可以调用滚动事件,然后隐藏软输入键盘,如果它当前使用毛伊岛社区工具包可见的话。


Here's the code snippet for your reference:

以下是供您参考的代码片段:


XMAL:

XMAL:


 <StackLayout> 
<SearchBar Placeholder="Rechercher..." TextChanged="SearchBar_TextChanged" x:Name="searchBar"/>
<ListView x:Name="ListView_Abonnes" HasUnevenRows="True" SelectionMode="None" IsPullToRefreshEnabled="True" Refreshing="ListView_Refreshing" Scrolled="ListView_Abonnes_Scrolled">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" >
</TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>


Code-behind:

代码隐藏:


private void ListView_Abonnes_Scrolled(object sender, ScrolledEventArgs e) 
{
searchBar.HideKeyboardAsync(CancellationToken.None);
}


更多回答

Thanks You. But unfortunatly the list is scrolled when type in search bar. So with that method, keyboard is closing each time we type a char in searchbar

谢谢你。但不幸的是,当在搜索栏中输入时,列表被滚动。因此,每次我们在搜索栏中键入字符时,键盘都会关闭

@Mickaël After typing in the SearchBar, the keyboard would close, if you want it to show again, you may need to click the SearchBar again to get it foucsed to show the keyboard.

@米卡埃L在搜索栏输入后,键盘会关闭,如果你想让它再次显示,可能需要再次点击搜索栏才能让它显示键盘。

@AlexandarMay-MSFT thanks for your post linking "Hide Keyboard" (a.k.a. soft input) to the CommunityToolkit.Maui NuGet. I was totally unaware of this IP. What a great find!

@AlexandarMay-MSFT感谢您的帖子链接“隐藏键盘”(又名软输入)到社区工具包.Maui NuGet。我完全不知道这个IP。多么伟大的发现啊!

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com