Listview中不可检索的ListItems
因此,我正在使用Xamarin表单进行我的第一个项目,我遇到了一个问题:在Android Emulator上,我的listview中的项不可点击/不可选择。我不知道它在iOS上是否有效。希望你们能帮助我 以下是我所做的: 当用户在搜索栏中输入代码时,将observableCollection中对象的代码与搜索栏中的文本进行比较。如果它与任何对象中的任何代码相匹配,则相关对象将放入我用于Listview.ItemSource的IEnumerable中。我可以显示收藏,但当我点击一个项目时,绝对不会发生任何事情 重要提示:当我发送某个项目的垃圾邮件时,它有时会起作用 以下是视图中的匹配代码搜索方法:Listview中不可检索的ListItems,listview,xamarin.forms,listviewitem,selecteditem,Listview,Xamarin.forms,Listviewitem,Selecteditem,因此,我正在使用Xamarin表单进行我的第一个项目,我遇到了一个问题:在Android Emulator上,我的listview中的项不可点击/不可选择。我不知道它在iOS上是否有效。希望你们能帮助我 以下是我所做的: 当用户在搜索栏中输入代码时,将observableCollection中对象的代码与搜索栏中的文本进行比较。如果它与任何对象中的任何代码相匹配,则相关对象将放入我用于Listview.ItemSource的IEnumerable中。我可以显示收藏,但当我点击一个项目时,绝对不会
async void Search(object sender, EventArgs e)
{
string CodeStr = RestoSearchBar.Text.ToLower();
RestaurantListViewModel restaurantViewModel = new RestaurantListViewModel();
var collec = restaurantViewModel.RestaurantCollector;
IEnumerable<Restaurant> SearchResults = null;
SearchResults = collec.Where(R => R.sCode.ToLower().Contains(CodeStr)).ToArray();
if (SearchResults.Count() == 0)
{
await DisplayAlert(AppResources.Error, AppResources.ErrorMessage, "OK");
}
else
{
//Recherche dans la base de données
await Navigation.PushAsync(new Page5_ListeRestau(CodeStr, SearchResults));
}
}
提前谢谢
SelectedItem
是一个属性,包含对当前所选项目的引用ItemSelected
是一个事件,在选择项目时触发
您希望将事件处理程序分配给事件,而不是属性
另外,
ListView
是可滚动的,因此在其中嵌套另一个可滚动元素不是一个好主意。SearchListView\u itemstapped做什么?我不认为在您的单元格中设置ScrollView
是最好的主意,这可能是导致您失败的原因problem@FabriBertani我编辑了这篇文章@GeraldVersluis是否有其他方法可以在不牺牲滚动网格功能的情况下完成此操作?首先,取消滚动视图,其次使用ItemSelected
而不是SelectedItem
非常感谢!
public Page5_ListeRestau(string CodeResto, IEnumerable<Restaurant> SearchResults)
{
InitializeComponent();
code = CodeResto;
if (SearchResults != null)
{
SearchListView.ItemsSource = SearchResults;
}
else
{
DisplayAlert(AppResources.Error, AppResources.ErrorMessage, "OK");
}
<ListView
x:Name="SearchListView"
HasUnevenRows="true"
Grid.Row="2"
HorizontalOptions="StartAndExpand"
VerticalOptions="StartAndExpand"
SeparatorVisibility="Default"
SelectedItem="SearchListView_ItemTapped"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ScrollView>
<Grid Margin="0,20,0,0" x:Name="Items">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" HorizontalOptions="StartAndExpand" Source="{Binding sImage}" BackgroundColor="Transparent" HeightRequest="50" />
<Grid Grid.Column="1" Margin="10,0,0,0">
<Label Grid.Row="0" TextDecorations="Underline" Text="{Binding sName}" FontSize="Large" TextColor="Black" Margin="10,0,0,0"/>
<Label Grid.Row="1" Text="{Binding sAddress}" Margin="10,0,0,0"/>
</Grid>
</Grid>
</ScrollView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
public void SearchListView_ItemTapped(object sender, ItemTappedEventArgs e)
{
var details = e.Item as Restaurant;
Navigation.PushAsync(new Page1_menuNavig(details));
}