Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
990
XamComboEditor AllowMultipleSelection SelectedItems
posted

Hi team,

this is very cool control, but I am for some reason unable to bind SelectedItems to my VM.

<ig:XamComboEditor EmptyText="Select Region..." IsEnabled="{Binding ElementName=_regionSearch, Path=IsChecked}" Grid.Column="1" SelectedItem="{Binding SelectedRegions, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}" IsEditable="False" CheckBoxVisibility="Visible" AllowMultipleSelection="True" ItemsSource="{Binding Regions}"/>

VM

public ObservableCollection<IdentifierDetail> SelectedRegions{

get { return _selectedRegions; }

set {

if (_selectedRegions == null

)

_selectedRegions = new ObservableCollection<IdentifierDetail>();

_selectedRegions = value;

OnPropertyChanged("SelectedRegions");

}}

  public class IdentifierDetail
  {
    private string idField;
    private string nameField;

    public string Id
    {
      get
      {
        return this.idField;
      }
      set
      {
        this.idField = value;
      }
    }

    public string Name
    {
      get
      {
        return this.nameField;
      }
      set
      {
        this.nameField = value;
      }
    }

    public override string ToString()
    {
      if (!string.IsNullOrEmpty(Name))
        return Name;
      return string.Empty;
    }

    public override int GetHashCode()
    {
      return ToString().GetHashCode();
    }

    public override bool Equals(object obj)
    {
      IdentifierDetail other = (obj as IdentifierDetail);
      if (other != null && other.Id != null && other.Name != null)
      {
        return Id.Equals(other.Id) && Name.Equals(other.Name);
      }
      return false;
    }


  }

Please help me.

 

thanks

 

Parents
No Data
Reply
  • 138253
    Offline posted

    Hello Anant,

     

    Thank you for your post. I have been looking into it and I created a sample project for you with the functionality you want. Basically the SelectedRegions collection should be ObservableCollection of objects and the SelectedItems Property of the XamComboEditor should be bind to a Source, not via the DataContext. Please let me know if this helps you or you have further questions on this matter.

     

    Looking forward for your reply.

    XamComboEditorSelectedItems.zip
Children