Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9298445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:19:38+00:00 2026-06-18T22:19:38+00:00

I am trying to bind the results from a collection in my ViewModel to

  • 0

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.

XAML:

DataContext="clr-namespace:Alliance.Library.Email.EmailViewModel"

  <ComboBox x:Name="cboProviders" ItemsSource="{Binding Source=AddressProviders}" DisplayMemberPath="ProviderName" Grid.Row="0" Grid.Column="1"></ComboBox>

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.

Code:

This is in my VeiwModel “EmailViewModel.cs”:

 public IEnumerable<IEmailAddressesProvider> AddressProviders { get; set; }

This is my interface “IEmailAddressesProvider”:

    public interface IEmailAddressesProvider
    {
        string ProviderName { get; }
        IEnumerable<EmailAddress> GetEmailUsers();
    }
}

Code for “EmailAddressProviders.cs” that contains GetEmailUsers():

[Export(typeof(IEmailAddressesProvider))]
    public class EmailAddressProvider : IEmailAddressesProvider
    {
        #region Private Properties

        private static readonly IEncryptionService encryptionService = AllianceApp.Container.GetExportedValue<IEncryptionService>();

        #endregion

        public string ProviderName
        {
            get { return "Alliance Users"; }
        }

        public IEnumerable<EmailAddress> GetEmailUsers()
        {
            IUserRepository userRepo = AllianceApp.Container.GetExportedValue<IUserRepository>();
            IEnumerable<User> users = userRepo.GetAllUsers().Where(a => a.IsDeleted == false).OrderBy(a => a.UserID).AsEnumerable();

            List<EmailAddress> AddressList = new List<EmailAddress>();

            foreach (var user in users)
            {
                if (user.DisplayName != null && user.EmailAddress != null && user.DisplayName != string.Empty && user.EmailAddress != string.Empty)
                    AddressList.Add(new EmailAddress() { DisplayName = encryptionService.DecryptString(user.DisplayName), Email = encryptionService.DecryptString(user.EmailAddress) });
            }

            AddressList.OrderBy(u => u.DisplayName);

            return AddressList;

        }
    }

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:19:39+00:00Added an answer on June 18, 2026 at 10:19 pm

    If you don’t really have a StaticResource anywhere, you should not use it. For your situation, you most probably want to do the following:

    Change GetEmailUsers() method to a property (you can only bind properties, not methods return values):

    public interface IEmailAddressesProvider
    {
        string ProviderName { get; }
        IEnumerable<EmailAddress> EmailUsers { get; set;};
    }
    

    Then change your XAML to this:

    <ComboBox x:Name="cboProviders" ItemsSource="{Binding AddressProviders.EmailUsers}" Grid.Row="0" Grid.Column="1"></ComboBox>
    

    Also make sure you set DataContext for your Page to your ViewModel instance.

    EDIT: Okay, just understood that you’re setting DataContext wrongly. Based on what you’ve written, you seem to set it somewhere in your XAML like this:

    DataContext="clr-namespace:Alliance.Library.Email.EmailViewModel"
    

    This essentially means you’re setting your data context to a string, and then try to bind to that string’s properties, which certainly don’t exist. I’d recommend you to check your runtime output for a binding errors to make sure this is the case.

    If that’s really so, then you need to set DataContext correctly. The easiest option to begin with is to do this in your view’s constructor:

    public MyView()
    {
        DataContext = new Alliance.Library.Email.EmailViewModel();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to bind results returned from queries with dynamic where clauses to
I am trying to bind a model coming from the server over json to
I'm trying to bind a combobox to a ObservableCollection.When the form is displayed the
I'm trying to bind a XAML ComboBox so that its list items are the
I'm trying to loop over a set of results using MySQLi and the bind
I have this GridView that I'm trying to bind data to and I need
I am trying to create a table using CGI.pm. The table would contain results
I'm having some problems with the code below. What I'm trying to do is
I am trying to convert some code from perl to php. Perl code looks
I'm getting very frustrating results when trying to bind parameters to a PDO prepared

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.