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

Binding inside SfListView

Thread ID:

Created:

Updated:

Platform:

Replies:

147319 Sep 5,2019 10:23 PM UTC Sep 10,2019 11:39 AM UTC Xamarin.Forms 6
loading
Tags: SfListView
David Saylor
Asked On September 5, 2019 10:23 PM UTC

Hello, we are having trouble with binding a custom control inside of a SfListView.ItemTemplate to a property on the containing control.  The binding seems correct as far as I can tell -- the name of the containing control is ThisControl, it has a property named ViewModel, which has an ICommand property ToggleItemCommand.  The property is a custom BindableProperty, but it also seems correct.

The item shows with the correct Text value. Even though the binding is set, and everything "seems" correct, we do not see any value from the binding for the Command property.  The Set is never called.  I can only think that it is something about the list view that we are doing wrong.  Could you please offer some help?

The hopefully relevant portions are shown below.  Syncfusion.Xamarin.SfListView version is 17.2.0.47


<Grid  Grid.Row="4" BackgroundColor="White">
    <listView:SfListView x:Name="selectedChildBucketItems" FlowDirection="LeftToRight" ItemsSource="{Binding SelectedChildBucket.Items}" Margin="16,16,0,0" ItemSize="121" SelectionBackgroundColor="Transparent" >
        <listView:SfListView.LayoutManager>
            <listView:GridLayout SpanCount="4" />
        </listView:SfListView.LayoutManager>
        <listView:SfListView.ItemTemplate>
            <DataTemplate>
                <MyControls:MyButtonListButton Text="{Binding Description}" Command="{Binding ViewModel.ToggleItemCommand, Source={Reference ThisControl}}" CommandParameter="{Binding }" IsToggled="{Binding IsSelected, Mode=TwoWay, Converter={StaticResource nullableBoolConverter}}" FontSize="18" FontFamily="Arial"/>
            </DataTemplate>
        </listView:SfListView.ItemTemplate>
    </listView:SfListView>
</Grid>

public partial class MVButtonListButton : ContentView, INotifyPropertyChanged
{
    public static readonly BindableProperty CommandProperty = BindableProperties.Create(nameof(Command), returnType: typeof(ICommand), declaringType: typeof(MyButtonListButton), defaultValue: null, propertyChanged: (obj, oldCommand, newCommand) => (obj as MyButtonListButton).CommandChangedHandler((ICommand)oldCommand, (ICommand)newCommand));

    public ICommand Command
    {
        get => (ICommand)GetValue(CommandProperty);
        set => SetValue(CommandProperty, value);
    }

    private void CommandChangedHandler(ICommand oldCommand, ICommand newCommand)
    {

    }
}

Sangeetha Raju [Syncfusion]
Replied On September 6, 2019 02:13 PM UTC

Hi David, 
 
We would like to let you know that if  you apply binding to SfListView through ViewModel, you can access the ViewModel Command as like below mentioned code snippet. Since we don’t have complete xaml snippet of “ThisControl” reference we have done the binding using SfListView binding context to access ViewModel. 
 
<listView:SfListView.ItemTemplate> 
   <DataTemplate> 
      <MyControls:MyButtonListButton Text="{Binding Description}" Command="{Binding Path=BindingContext.ToggleItemCommand, Source={x:Reference selectedChildBucketItems}}" CommandParameter="{Binding .}" IsToggled="{Binding IsSelected, Mode=TwoWay, Converter={StaticResource nullableBoolConverter}}" FontSize="18" FontFamily="Arial"/> 
   </DataTemplate> 
</listView:SfListView.ItemTemplate> 
 
Can you please check with the above mentioned codes and please let us know if you require any further assistance. 
 
Regards, 
Sangeetha Raju. 


David Saylor
Replied On September 6, 2019 05:42 PM UTC

Thanks, we will try that.

David Saylor
Replied On September 6, 2019 06:55 PM UTC

YES, this worked for us. Thank you!

Sangeetha Raju [Syncfusion]
Replied On September 9, 2019 06:03 AM UTC

Hi David, 
 
We are glad for our solution works. Thanks for the update.  
 
Please let us know if you require further queries or else you can close the incident. 
 
Regards, 
Sangeetha Raju. 


David Saylor
Replied On September 9, 2019 01:16 PM UTC

I actually don't see where the option to close this incident is.  Can you show me?

Sangeetha Raju [Syncfusion]
Replied On September 10, 2019 11:39 AM UTC

Hi David, 
 
Sorry for our previous update. This is the open forum which can't be closed at your end. So, please ignore previous update and let us know if you have any further queries. 
 
Regards, 
Sangeetha Raju. 


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