We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

sfListView in Sfpopup

Thread ID:

Created:

Updated:

Platform:

Replies:

146292 Jul 30,2019 06:32 AM UTC Aug 26,2019 07:12 PM UTC Xamarin.Forms 3
loading
Tags: SfPopup
Leon
Asked On July 30, 2019 06:39 AM UTC

I am using a sflistview inside a sfpopup

when I try to access the sflistview in code behind to read the selected value I always get null.

I tried:
this.FindByName("MyListView")

(SfListView)oSfPopupLayout.FindByName("MyListView")

sfpopup xaml:


               
                   
                           HeaderTitle="Please select default project."
                           ShowFooter="True">
                       
                           
                               
                                    ItemsSource="{Binding ActiveProjects}">
                                   
                                       
                                           
                                               
                                                   
                                                       
                                                           
                                                       
                                                       
                                                           
                                                       
                                                       

 Any help would be appreciated.

Subburaj Pandian Veluchamy [Syncfusion]
Replied On July 30, 2019 08:54 AM UTC

Hi Juan,  
 
Thank you for contacting Syncfusion support. 

We have checked your requirement of “Accessing DataTemplate elements in code behind which is hosted in Xaml” and it is not possible. You must need to derive in code behind to access the DataTempalte elements, which is a limitation. Based on the code, your requirement of accessing ListView can be achieved by initializing the ListView in the code behind and you can access. 
 
Please let us know, if you have any concern. 
 
Regards,
Subburaj Pandian V    


Matthew Bailey
Replied On August 23, 2019 01:05 PM UTC

How would I go about building it from the code behind?

I'm using Xamarin's CollectionView and having the same issues, but if you can explain how to build it in the code behind so I can access the SelectedItems values I'd greatly appreciate it.

My DataTemplate holds two labels in a StackLayout and gets populated from an ItemSource in the ViewModel. I understand how to build most of the content, but how to get the binding to work from code behind isn't something I understand completely. Can you help walk me through using SFListView for something like this?

<sfPopup:PopupView.ContentTemplate>
    <DataTemplate>
        <CollectionView
            x:Name="CodesCollection"
            ItemsSource="{Binding CodesReturn}"
            SelectionMode="Multiple"
            SelectedItems="{Binding CodesSelected, Mode=TwoWay}">
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" >
                        <StackLayout Orientation="Horizontal" Margin="10,5,10,1">
                            <Label
                                Margin="10,0,0,0"
                                Text="{Binding Code}"
                                FontSize="Default"
                                FontAttributes="Bold"
                                HorizontalOptions="Start"/>
                            <Label
                                Margin="0,0,10,0"
                                Text="{Binding Name}"
                                FontSize="Default"
                                FontAttributes="Bold"
                                HorizontalOptions="EndAndExpand"
                                HorizontalTextAlignment="End"/>
                        </StackLayout>
                        <BoxView
                            VerticalOptions="End"
                            HorizontalOptions="FillAndExpand"
                            Margin="15,2,15,2"
                            HeightRequest="2"
                            BackgroundColor="{StaticResource DarkGrey}"/>
                    </StackLayout>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </DataTemplate>
</sfPopup:PopupView.ContentTemplate>


Balasubramani Sundaram [Syncfusion]
Replied On August 26, 2019 07:12 PM UTC

Hi Matthew,  
 
Thank you for contacting Syncfusion support.   
 
Based on the provide details, we have created a sample which has created the collection view at code behind and set the item source and bind inside the SfPopupLayout. You could able to access the collection view when selecting the items with that instance. 
 
Please refer the following sample and code snippet, 
 
Code Snippet [C#] 
 
private CollectionView _collectionView; 
public MainPage() 
{ 
    ........ 
    _collectionView = new CollectionView(); 
    _collectionView.ItemsSource = viewModel.BookInfo; 
    _collectionView.SelectionMode = SelectionMode.Multiple; 
    
    _collectionView.ItemTemplate = new DataTemplate(() => { 
        StackLayout _ParentstackLayout = new StackLayout(); 
        ///---------------------------------------------- 
        StackLayout _stackLayout = new StackLayout(); 
        Label _labelOne = new Label(); 
        ...... 
        _labelOne.SetBinding(Label.TextProperty, "BookName", BindingMode.TwoWay); 
        Label _labelTwo = new Label(); 
        ....... 
        _labelTwo.SetBinding(Label.TextProperty, "BookDescription", BindingMode.TwoWay); 
        _stackLayout.Children.Add(_labelOne); 
        _stackLayout.Children.Add(_labelTwo); 
        //-------------------------------------------------- 
 
        BoxView _boxView = new BoxView(); 
        ...... 
         
        _ParentstackLayout.Children.Add(_stackLayout); 
        _ParentstackLayout.Children.Add(_boxView); 
 
        return _ParentstackLayout; 
    }); 
 
    _popupContent.ContentTemplate = new DataTemplate(() => { 
        return _collectionView; 
    }); 
} 
 
 
 
We hope this helps. Please let us know, if you need any further assistance. 
 
Regards,
Balasubramani Sundaram.
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon