Hello,
Welcome to our Microsoft Q&A platform!
I'm so sorry I can't reproduce this issue, I suspect that it caused by the ViewModel, so I display a tableview without ViewModel
, it works well.
XAML
<ListView
x:Name="list"
ItemsSource="{Binding Items}"
SeparatorVisibility="None"
HasUnevenRows="False"
RowHeight="100"
BackgroundColor="Transparent"
ItemSelected="OnItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding }" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Code behind
public ObservableCollection<string> Items { get; set; } = new ObservableCollection<string>();
public MainPage()
{
InitializeComponent();
for (int i = 0; i < 10; i++){
Items.Add(i.ToString());
}
BindingContext = this;
}
protected override void OnAppearing()
{
base.OnAppearing();
}
async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
{
Console.WriteLine("has been selected");
}
Then, I add the ViewMode and Model, it also works.
XAML
<DataTemplate>
<TextCell Text="{Binding Text}" />
</DataTemplate>
Code behind
public partial class MainPage : ContentPage
{
public ItemViewModel Items { get; set; } = new ItemViewModel();
public MainPage()
{
InitializeComponent();
BindingContext = Items;
}
protected override void OnAppearing()
{
base.OnAppearing();
}
async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
{
Items.SelectedItem = (Item)args.SelectedItem;
await Items.TaskHandleSelectItemAsync();
}
}
ItemViewModel
public class ItemViewModel
{
public ObservableCollection<Item> Items { get; set; } = new ObservableCollection<Item>();
public Item SelectedItem { get; set; }
public ItemViewModel()
{
for (int i = 0; i < 10; i++)
{
Item item = new Item { Text = i.ToString() };
Items.Add(item);
}
}
public async Task TaskHandleSelectItemAsync()
{
Console.WriteLine("has been selected" + SelectedItem.Text);
}
}
Model
public class Item
{
public string Text { get; internal set; }
}
I change the HeightRequest, it also works. The biggest difference is that you use _viewModel
and IsEnabled="{Binding IsBusy, Converter={StaticResource negate}}"
and SetListHeightRequest
, you could try to check these methods.
In addition, would you mind sharing a demo to me so that I can reproduce this issue and test it?
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.