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 1014821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:18:30+00:00 2026-05-16T10:18:30+00:00

so I have a custom class in a list. I can’t seem to get

  • 0

so I have a custom class in a list. I can’t seem to get the list and a combobox to bind though. The list should display all the name values of the customclass. I want to do this in code. Any help most appreciated (as ever!).

It’s best if I give some code snippets I think.

The class:

public class Asset : IComparable<Asset>
{

    ...

    public String name { get { return _name; } set { _name = value; } }

    ...
}

List and my attempted binding, is it that ComboBox.ItemBindingGroupProperty is the wrong thing?

List<Asset> assetsForCbos = new List<Asset>();
assetsForCbos.Add(new Asset("example asset"));

Binding bindingAssetChoice = new Binding();
bindingAssetChoice.Source = assetsForCbos;
bindingAssetChoice.Path = new PropertyPath("name");
bindingAssetChoice.Mode = BindingMode.OneWay;
cboAsset1.SetBinding(ComboBox.ItemBindingGroupProperty, bindingAssetChoice);

In the XAML I have

<ComboBox Height="23"
ItemsSource="{Binding}"
HorizontalAlignment="Left" 
Margin="10,8,0,0" 
Name="cboAsset1" 
VerticalAlignment="Top" 
Width="228" 
IsReadOnly="True" 
SelectedIndex="0"/>
  • 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-05-16T10:18:30+00:00Added an answer on May 16, 2026 at 10:18 am

    What you can try is in xaml set ItemsSource="{Binding}" and in code behind set

    cboAsset1.DataContext = assetsForCbos;
    

    Personally my preference is to do all binding in Xaml so if there is a change needed i just have to look at the xaml.

    EDIT: If you wanted to show the name property, instead of Namespace.Asset, you could of done one of the following

    1. Override ToString in the Asset class to return the asset name.
      Note: This will not change, therefore if the name changes in the Asset object, this will not update in the view.
    2. Create a DataTemplate which contains a StackPanel(light weight layout container of my choice) and a TextBlock inside the StackPanel which binds to the name property. As your creating the ComboBox in code here is how you could do it.

      // Create Data Template
      DataTemplate itemsTemplate = new DataTemplate();
      itemsTemplate.DataType = typeof (Asset);
      
       // Set up stack panel
       FrameworkElementFactory sp = new FrameworkElementFactory(typeof (StackPanel));
       sp.Name = "comboStackpanelFactory";
       sp.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
      
       // Set up textblock
       FrameworkElementFactory assetNameText = new FrameworkElementFactory(typeof (TextBlock));
       assetNameText.SetBinding(TextBlock.TextProperty, new Binding("name"));
       sp.AppendChild(assetNameText);
      
       // Add Stack panel to data template
       itemsTemplate.VisualTree = sp;
      
       // Set the ItemsTemplate on the combo box to the new data tempalte
       comboBox.ItemTemplate = itemsTemplate;
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom class Contact . I am trying to bind a List<Contact>
I have a custom class: public class Person { public String Name { get;
I have a custom class loader so that a desktop application can dynamically start
I have a string variable that represents the name of a custom class. Example:
I have a custom attribute which can be assigned to a class, [FooAttribute] .
How can I use reflection to create a generic List with a custom class
I have a list of RowData items (a custom class). A RowData item contains
I have a custom class that implements that IComparable. This class is stored in
I have a custom class that implements ICollection , and this class is readonly,
Say you have a custom class call it Foo. When you then have an

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.