Binding data and Tap Event - UI Kit Page ArticleTitlePage

Hi All,

I have a question regarding the use of a specific UI page so I may understand its associated structure if anyone can assist.

The ArticleTitlePage has a listview as follows:

            <listView:SfListView
                x:Name="SfListView"
                Grid.Row="1"
                Margin="8"
                AutoFitMode="Height"
                HeaderTemplate="{StaticResource HeaderView}"
                HorizontalOptions="FillAndExpand"
                ItemSpacing="8"
                ItemTemplate="{StaticResource HorizontalArticleView}"
                ItemsSource="{Binding LatestStories}"
                SelectionBackgroundColor="Transparent"
                TapCommand="{Binding ItemSelectedCommand}"
                VerticalOptions="FillAndExpand">

                <!--  Layout to customize no. of columns in SfListView  -->
                <listView:SfListView.LayoutManager>
                    <listView:GridLayout x:Name="GridLayout" SpanCount="{OnIdiom Phone=2, Tablet=3, Desktop=5}" />
                </listView:SfListView.LayoutManager>

            </listView:SfListView>


Its template is bound with a data set of 'LatestStories' which includes 'Name', 'Author', 'Date'.. etc.

I wish to retrieve a selected value back (ie. Author) when it is tapped/selected but cannot figure out how to do this despite some research.

The ViewModel includes the following method which fires successfully on tap:

        /// Invoked when an item is selected.
        private void ItemSelected(object obj)
        {
            // Do something
        } 

Appreciate your help and thanks in advance.

Cheers
Alex

3 Replies

DV Divya Venkatesan Syncfusion Team March 12, 2020 12:23 PM UTC

Hi Alex, 
 
Greetings from Syncfusion. 
 
We have achieved your requirement to retrieve selected value as shown in the below code snippets. 
 
Code snippets [C#]: 
 
/// <summary> 
/// Invoked when an item is selected. 
/// </summary> 
/// <param name="obj">The Object</param> 
private void ItemSelected(object obj) 
{ 
    var model = (obj as Syncfusion.ListView.XForms.ItemTappedEventArgs)?.ItemData as Model; 
    var author = model?.Author; 
    Application.Current.MainPage.DisplayAlert("", author, "ok"); 
} 
 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Divya Venkatesan 



AK Alex Kadow March 12, 2020 07:48 PM UTC

Hi Divya,

Thanks very much for your reply and help.

Works like a charm!

Thanks again
Alex


DV Divya Venkatesan Syncfusion Team March 13, 2020 06:07 AM UTC

Hi Alex, 
 
Thanks for the update. We are glad to know that the given solution works.  
 
Please let us know if you need any further assistance. 
 
Regards,  
Divya Venkatesan 


Loader.
Up arrow icon