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

SfComboBox SelectionChanged connection to MVVM

Thread ID:

Created:

Updated:

Platform:

Replies:

146822 Aug 21,2019 04:29 PM UTC Aug 22,2019 01:22 PM UTC Xamarin.Forms 1
loading
Tags: SfComboBox
Matthew Bailey
Asked On August 21, 2019 04:29 PM UTC

I'm trying to use a ComboBox to initiate a Command to open a SfPopupView, but I can't quite seem to get the Command linking set up.


I thought doing something like this:
<combobox:SfComboBox
      DisplayMemberPath="Category"
      VerticalOptions="FillAndExpand"
      Grid.Column="0"
      Grid.Row="1"
      x:Name="SelectByDropDown"
      MultiSelectMode="None"
      TextSize="Small"
      DropDownTextSize="Small"
      DropDownCornerRadius="2"
      SelectedItem="{Binding SelectBySelection}"
      DropDownTextColor="{StaticResource DarkGrey}"
      SelectionChanged="{Binding SelectByChanged_Behavior}"
      DataSource="{Binding SelectionCriteria}"/>

And in my code behind I have:
public ICommand SelectBySelection_Behavior
{
      get
      {
              return new Command(() => CallForSelectionCriteria());
      }
}
public void CallForSelectionCriteria()
{
     
}

I can't figure out how to open the SfPopupView whenever SelectedItem changes. Can someone help?

Muneesh Kumar G [Syncfusion]
Replied On August 22, 2019 01:22 PM UTC

Hi Matthew Bailey, 
 
Greetings from Syncfusion.  
 
We have analyzed your requirement “How to open the SfPopupView whenever SelectedItem changes” from our side. We have prepared the simple sample for your requirement. Please try the attached below sample and let us know if you have any concern on this. 
 
Code Snippet: 
<StackLayout> 
        <combobox:SfComboBox IsEditableMode="True" DataSource="{Binding EmployeeCollection}" DisplayMemberPath="Name"> 
            <combobox:SfComboBox.Behaviors> 
                <local:SelectionChangedBehavior/> 
            </combobox:SfComboBox.Behaviors> 
        </combobox:SfComboBox> 
    </StackLayout> 
public class SelectionChangedBehavior : Behavior<SfComboBox> 
    { 
        public ICommand SelectBySelection_Behavior 
        { 
            get 
            { 
                return new Command(() => CallForSelectionCriteria()); 
            } 
        } 
        public void CallForSelectionCriteria() 
        { 
            // This method called while select the item from suggestion box in SfComboBox. You can open the SfPopupView whenever SelectedItem changes. 
        } 
        protected override void OnAttachedTo(SfComboBox bindable) 
        { 
            bindable.SelectionChanged += Bindable_SelectionChanged; 
            base.OnAttachedTo(bindable); 
        } 
        private void Bindable_SelectionChanged(object sender, SelectionChangedEventArgs e) 
        { 
            SelectBySelection_Behavior.CanExecute(true); 
            SelectBySelection_Behavior.Execute(true); 
        } 
        protected override void OnDetachingFrom(SfComboBox bindable) 
        { 
            bindable.SelectionChanged -= Bindable_SelectionChanged; 
            base.OnDetachingFrom(bindable); 
        } 
    } 
 
Sample Link: 
 
Please check the above sample and let us know if you require any further assistance on this. 
 
Thanks, 
Muneesh Kumar G. 
 


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