Xamarin NetStandard SfListview Item tapped event not firing? - xamarin.forms

This is just as the title suggests. I've updated my Xamarin Forms project to a 1.6 NetStandard project and now the tapped event on my SfListView isn't working (It just doesn't fire at all).
Does anyone has any suggestions of what could be wrong or have faced anything like this?
EDIT
this is xaml code for SfListView:
<StackLayout HeightRequest="15" Grid.Row="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<xForms:SfListView Orientation="Horizontal" ItemSize="128" ItemsSource="{Binding Categories}" SelectionBackgroundColor="Transparent" IsScrollBarVisible="False">
<xForms:SfListView.ItemTemplate>
<DataTemplate>
<cells:CategoryCell />
</DataTemplate>
</xForms:SfListView.ItemTemplate>
<xForms:SfListView.Behaviors>
<behaviors:SfSelectedItemBehavior Command="{Binding FilterCommand}" />
</xForms:SfListView.Behaviors>
</xForms:SfListView>
</StackLayout>
this structure was working before the update. I use a behavior for item selection.

We have checked with the reported query “SfListView ItemTapped event does not trigger after updating the NetStandard Library” from our side. Unfortunately the reported issue does not occur at our end and the ItemTapped event is fired as expected.
For your reference, we have attached the working sample link below.
Sample link: http://www.syncfusion.com/downloads/support/directtrac/190562/ze/SfListViewSample-670965361
Can you please check in your device whether the issue reproduces in our sample also?
If so, Can you please share the below details?
Whether the reported issue occurs in particular device or all devices? (Can you please share the details of your tested device)
Whether the issue is produced in particular platform?
Whether the issue is produced in particular version of Xamarin.Forms and SfListView? (In our sample, we used XForms (v2.3.4.280) and SfListView(v15.3.0.33))
Also can you please share the share the template in which the SfListView items are loaded?

Related

How tell command (on page) which control was pressed?

i have a big knot in my brain.
The current Situation is the following:
in my xamarin Forems App i have on some Pages a UserControl (House) witch Contains multiple Controls (Floor) and this has also multiple Controls (Rooms) in it.
This is all working perfectly and i have coll control for each room over a HouseControler Class
On my RoomControl i have:
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference Root}, Path=RoomTappedCommand}" />
</Grid.GestureRecognizers>
this is totally perfekt. and i got my command perfectly fired in the Breakpoint.
But what i want to acheve is to open nut just an alert but a custom Popup with a Navigation from the current Page with the Informations of the Tapped Room.
So in need do pass somehow the informations from the RoomControl up to the Page. But i dont know how.
i would love to read some tipps.
Thank you Guys =)
you can always get a reference to the currently active page using App.Current.MainPage. To display an alert, for example
App.Current.MainPage.DisplayAlert(...);

How to change the cancel icon in Xamarin Forms Shell SearchHandler

I have a Xamarin Forms Shell app where I have implemented the Shell SearchHandler. The cancel button shows a book image.
This only occurs on iOS - on Android, there is no cancel button.
My xaml looks like this:
<Shell.SearchHandler>
<controls:RouteSearchHandler
x:Name="RouteSearch"
BackgroundColor="White"
ClearPlaceholderCommand="{Binding ClearSearch}"
ClearPlaceholderIcon="{StaticResource Cancel}"
DisplayMemberName="Street1"
SearchBoxVisibility="{Binding TopSearchVisibility, Converter={StaticResource visibleConvert}}"
ShowsResults="True" />
</Shell.SearchHandler>
How do I change the cancel icon from a book to another fonticon or image?
It seems a potential issue , the team set a default(book) icon on Clear button.
Workaround
You can prepare a small/transparent image and place it in Resources folder in iOS project , and set ClearPlaceholderIcon with it, then the problem should be solved .
And Feel free to file the feature request on github :https://github.com/xamarin/Xamarin.Forms/issues.

CollectionView template calls converter incorrectly

Xamarin.Forms 5.0.0.2012, Visual Studio 2019 for Mac 8.10.16
I am encountering a problem (on both iOS and Android, on both emulators and physical devices) trying to call a Converter in the XAML describing a new screen in our app. This is the markup:
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:internal="clr-namespace:Views.Shared"
x:Class="Views.EditPage">
<ContentPage.Resources>
<internal:PictureNameToImageSourceConverter x:Key="PictureNameToImageSourceConverter" />
</ContentPage.Resources>
...
<CollectionView
x:Name="picturesView"
ItemsLayout="HorizontalList"
HeightRequest="90">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame HasShadow="False" Padding="5">
<Image
HeightRequest="80"
Source="{Binding Path=., Converter={StaticResource PictureNameToImageSourceConverter}}" />
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
The CollectionView.ItemsSource value is set in code to a List<string> instance. When the List has no items, the screen displays correctly. When it does have items the app crashes as the screen appears. If I launch the app attached to the VS debugger, the screen freezes before the crash, and I never get any information.
This converter is well tested and is used several other places in the app with no problem. When I replace the Image with <Label Text="{Binding Path=.}"/> the text items are displayed as expected, so it doesn't look like a binding or Path syntax error.
Is there something I'm not seeing or not aware of in the markup that's causing this? Or can anyone suggest further debugging I haven't thought of?
UPDATE
A breakpoint on the very first line of the converter was never reached.
EDIT in response to comments:
From the EditPage codebehind:
public partial class EditPage : ContentPage
{
internal List<string> PictureNames;
...
protected override void OnAppearing( )
{
base.OnAppearing();
picturesView.ItemsSource = PictureNames;
}
The PictureNames property is actually set by a different Page to which one navigates from the EditPage:
private void saveSelection_Click(object sender, System.EventArgs args)
{
creator.PictureNames = new List<string>();
foreach (SelectableItem<Picture> item in pictureItems)
{
if (item.IsSelected)
{
creator.PictureNames.Add(item.Item.PictureName);
}
}
Navigation.PopAsync();
}
pictureItems is a List acting as a ListView.ItemsSource on that screen, where pictures are selected or unselected.
UPDATE
After much setting of breakpoints, I've determined that the line picturesView.ItemsSource = PictureNames; is where the crash happens. It seems odd that it only happens when the template is showing an Image, but not a Label, seeing that the converter is never actually called.
UPDATE
The trick of adding the delay did get me to the breakpoint. And what I found is more puzzling than ever: The value parameter being passed to the Convert method of our converter is null. This is the case whether coming back from the picture selection screen, or if I set the bound list in response to a Button rather than in OnAppearing, or if I just set it right in the page constructor.
In addition, when setting a breakpoint on the crashing line, when the display element in the template is a Label everything is as expected, but when the display element is an Image the debugger freezes when trying to look at those values. The problem is apparently something about the fact of calling a converter in this precise situation.
I tested that by adding a different converter to the template:
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame HasShadow="False" Padding="5" HeightRequest="{Binding Path=., Converter={StaticResource PictureNameToHeightConverter}}">
<Label Text="{Binding Path=.}" />
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
Exactly the same result: The value parameter passed to the Convert method is null even though the same bound value in the same template instance is displayed in the Label. If I set a breakpoint on the line assigning the ItemsSource property as before, the debugger freezes.
UPDATE
Finally beginning to suspect that I'm triggering some corner case bug in the framework, I replaced the CollectionView with a CarouselView, and it works correctly:
<CarouselView
x:Name="picturesView"
HeightRequest="90">
<CarouselView.ItemTemplate>
<DataTemplate>
<Frame HasShadow="False" Padding="5">
<Image
HeightRequest="80"
Source="{Binding Path=., Converter={StaticResource PictureNameToImageSourceConverter}}" />
</Frame>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
I'm adding this as an update to the question rather than as an answer because I still don't actually know the explanation.
I've seen some odd behavior when updating page details in OnAppearing.
Hard to put a finger on exactly when there will be a problem, but the fact that you navigated to another page, so this is OnAppearing during the "back" from that other page is probably a factor.
Try this:
protected override void OnAppearing( )
{
base.OnAppearing();
Device.BeginInvokeOnMainThread( async () => {
// Let the page appear on screen, before setting ItemsSource.
await System.Threading.Tasks.Task.Delay(200);
picturesView.ItemsSource = PictureNames;
});
}
At minimum, this should allow Xamarin to reach the breakpoint in the converter.
——————-
UPDATE
I don’t see any obvious flaw in the code you’ve posted.
You’ve narrowed it down to the line it crashes on.
Yet a breakpoint at start of converter is never reached.
As you say, this is a puzzling combination of facts.
Here is a test to do:
Put breakpoint on the line that crashes.
Copy the values in the list, to a text editor.
Add a button on the current page, that when pressed, fills the list with those same strings, hardcoded as a literal, then sets the ItemSource.
Start over, but this time press the button - Does this work or crash?
That is, remove all the complexity of going to another page, querying values, returning to this page.
I bet this will work. Then you’d have the best situation for debugging: a case that works vs. one that doesn’t.
After that, its “divide and conquer”. Start making the working one more like the broken one, and/or vice versa, until the culprit is identified.
You could try to pass data with the ways below when you do the navigation.
One way is to set the BindingContext to the page which you want to navigate to.
Use the Navigation.PushAsync to navigate the page and reset the BindingContext before the page navigated. You could check the thread i done before for more details. Xamarin Public Class data how to acess it properly
Or you could try to binding to a path property using MVVM.
<Image HeightRequest="80" Source="{Binding path, Converter={StaticResource PictureNameToImageSourceConverter}}" />
Another way is to pass the data to the page which you want to navigate through a Page Constructor.
For more details of this way, check the MS docs. https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical#passing-data-through-a-page-constructor
While it would be interesting to know why the CollectionView binding isn't behaving as expected in this specific situation, the number of hours spent trying to figure it out has definitely passed the point of diminishing returns, so I just added the images the old-fashioned way. I replaced the CollectionView with a StackLayout:
<StackLayout x:Name="picturesLayout" Orientation="Horizontal" />
And then just added framed images "by hand" in the OnAppearing method:
picturesLayout.Children.Clear();
foreach (string pictureName in PictureNames)
{
picturesLayout.Children.Add(new Frame { Padding = 5, HasShadow = false, Content = new Image { Source = ImageManager.ReadFromDisk(pictureName), HeightRequest = 80 } });
}
(ImageManager handles chores like keeping track of the full path to the appropriate directory.)

Xam.TabView Header is not scrollable in Xamarin forms

I am using Xam.Tabview plugin in my project.
Everything works fine except the header is not scrollable.
Below is my code:
<control:XFTabControl
x:Name="Tabcomponent"
VerticalOptions="FillAndExpand"
TabClicked="Tab_TabClicked"
HeaderHeight="40" FlowDirection="LeftToRight"
SelectedIndex="{Binding Index}">
<control:XFTabControl.XFTabPages>
**//Page1**
<tabview:XFTabPage>
<tabview:XFTabPage.Header>
<tabview:XFTabHeader>
<Label Text="Tab1"/>
</tabview:XFTabHeader>
</tabview:XFTabPage.Header>
<tabview:XFTabPage.Content>
<template:Page1></template:Page1>
</tabview:XFTabPage.Content>
</tabview:XFTabPage>
</control:XFTabControl.XFTabPages>
**//Page2**
<tabview:XFTabPage>
<tabview:XFTabPage.Header>
<tabview:XFTabHeader>
<Label Text="Tab1"/>
</tabview:XFTabHeader>
</tabview:XFTabPage.Header>
<tabview:XFTabPage.Content>
<template:Page2></template:Page2>
</tabview:XFTabPage.Content>
</tabview:XFTabPage>
</control:XFTabControl.XFTabPages>
</control:XFTabControl>
Any help is appreciated!
I am not sure if that package is still maintained or has documentation but the last update is 10 months ago, as an alternative you can try TabView from XamarinCommunityToolkit which is officially maintained by Xamarin.Forms team and the community.
Getting Started with the Xamarin Community Toolkit
TabView Docs https://learn.microsoft.com/en-us/xamarin/community-toolkit/views/tabview
Another option would be Sharpnado.Tabs package, Repo

Xamarin Forms: UWP app clicking is not working as expected

I have a weird issue with my UWP version of the xamarin forms project. The clicking is not working as expected. Sometimes no response when clicking items (button, image), and sometimes top items are opening when clicking an item.
Please watch this video for getting a clear idea. In this video, I am clicking the next button(Quiz page) several times, but no response. On the game page, the top item pages are opening when clicking an item. In android and ios, everything is working fine.
Version Details:
Xamarin Forms: 4.7.0.968
UWP target version: Windows 10, version 1903(10.0;Build 18362)
UWP Min version: Windows 10, Fall Creators Update(10.0; Build 16299)
Please help me to find the issue behind this. Thanks in advance.
Update
Button Code
<Button
Text="NEXT"
TextColor="White"
HorizontalOptions="EndAndExpand"
BackgroundColor="#f5c74c"
Clicked="NextButtonClicked"
WidthRequest="150"
HeightRequest="40"
FontSize="18"
BorderRadius="20"/>
public void NextButtonClicked(object sender, EventArgs args)
{
//action
}
I have solved this issue by updating the xamarin forms version to 4.8.0.1269.

Resources