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. Image for the cookie policy date

SfComboBox SelectionChanged connection to MVVM

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?

1 Reply

MK Muneesh Kumar G Syncfusion Team 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. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon