title: Binding the results of an IEnumerable<class> to a combobox
body: <p>I am trying to bind the results from a collection in my ViewModel to a combobox. Below is my code. Any help would be appreciated. If you need to see something else or need more information let me know.</p>
  
  <p>XAML:</p>
  
  <pre><code>DataContext="clr-namespace:Alliance.Library.Email.EmailViewModel"
  
    &lt;ComboBox x:Name="cboProviders" ItemsSource="{Binding Source=AddressProviders}" DisplayMemberPath="ProviderName" Grid.Row="0" Grid.Column="1"&gt;&lt;/ComboBox&gt;
  </code></pre>
  
  <p>That is my combobox. I realize that the code for that is completely wrong, but I am new so I was trying to approach it with trial and error.</p>
  
  <p>Code:</p>
  
  <p>This is in my VeiwModel "EmailViewModel.cs":</p>
  
  <pre><code> public IEnumerable&lt;IEmailAddressesProvider&gt; AddressProviders { get; set; }
  </code></pre>
  
  <p>This is my interface "IEmailAddressesProvider":</p>
  
  <pre><code>    public interface IEmailAddressesProvider
      {
          string ProviderName { get; }
          IEnumerable&lt;EmailAddress&gt; GetEmailUsers();
      }
  }
  </code></pre>
  
  <p>Code for "EmailAddressProviders.cs" that contains GetEmailUsers():</p>
  
  <pre><code>[Export(typeof(IEmailAddressesProvider))]
      public class EmailAddressProvider : IEmailAddressesProvider
      {
          #region Private Properties
  
          private static readonly IEncryptionService encryptionService = AllianceApp.Container.GetExportedValue&lt;IEncryptionService&gt;();
  
          #endregion
  
          public string ProviderName
          {
              get { return "Alliance Users"; }
          }
  
          public IEnumerable&lt;EmailAddress&gt; GetEmailUsers()
          {
              IUserRepository userRepo = AllianceApp.Container.GetExportedValue&lt;IUserRepository&gt;();
              IEnumerable&lt;User&gt; users = userRepo.GetAllUsers().Where(a =&gt; a.IsDeleted == false).OrderBy(a =&gt; a.UserID).AsEnumerable();
  
              List&lt;EmailAddress&gt; AddressList = new List&lt;EmailAddress&gt;();
  
              foreach (var user in users)
              {
                  if (user.DisplayName != null &amp;&amp; user.EmailAddress != null &amp;&amp; user.DisplayName != string.Empty &amp;&amp; user.EmailAddress != string.Empty)
                      AddressList.Add(new EmailAddress() { DisplayName = encryptionService.DecryptString(user.DisplayName), Email = encryptionService.DecryptString(user.EmailAddress) });
              }
  
              AddressList.OrderBy(u =&gt; u.DisplayName);
  
              return AddressList;
  
          }
      }
  </code></pre>
  
  <p>I am using MEF so as to how these values are being set, I like to call 'magic.' I didn't write the email portion of this. I am just trying to take care of getting the elements in the combobox. Thanks again! </p>