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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:40:18+00:00 2026-06-02T11:40:18+00:00

I have a listbox and a combobox described the XAML code below and I

  • 0

I have a listbox and a combobox described the XAML code below and I am trying to populate this listbox and combobox from within IronPython code and not XAML.

How can I populate this lists from within code?

On the list I need multiple columns.

<ComboBox
x:Name="comboBox1"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="53,14.223,0,0"
Width="54"
Height="19" />

<ListBox
x:Name="listBox1"
Grid.Column="0"
Grid.Row="0"
VerticalAlignment="Top"
Margin="0,30.223,14.5,0"
Height="368.639" HorizontalAlignment="Right" Width="442.619" />
  • 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-02T11:40:26+00:00Added an answer on June 2, 2026 at 11:40 am

    Using the accepted answer from following SO post: How do I bind to a ListBox in IronPython? I managed to populate and bind the m the combobox and list from Ironpython code.

    I will put all the code here in case anyone find himself/herself in the same situation:

    First there is the need of change in the XAML for the listbox to specify the binding:

    <DataTemplate x:Key="DataTemplate1">
                 <Grid>
                      <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="80"/>
                         <ColumnDefinition Width="*"/>
                      </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding Path=lproperty, FallbackValue=Property}" />
                <TextBlock Text="{Binding Path=lvalue, FallbackValue=Value}" Grid.Column="1" HorizontalAlignment="Right" Margin="0,0,-60,0" Width="360" />                
    
                </Grid>     
    
    
    </DataTemplate>
    

    then you need to also bind the listbox content to this template:

    <ListBox
                                x:Name="listBox1"
                                Grid.Column="0"
                                Grid.Row="0"
                                VerticalAlignment="Top"
                                Margin="0,30.223,14.5,0"
                                Height="368.639" HorizontalAlignment="Right" Width="442.619" 
                                ItemsSource="{Binding}" ItemTemplate="{DynamicResource DataTemplate1}"/>
    

    I will put also here the entire code that populates the combobox and listbox ssince it is not that big:

    import wpf
    from System.Windows import Application
    from Window1 import Window1
    from System.Windows.Controls import(ComboBox, 
        ComboBoxItem, ListBox, ListBoxItem)
    from System.Collections.ObjectModel import *
    from System.ComponentModel import *
    from System.Windows.Controls import *
    import pyevent 
    
    
    
    
    
    entries = {
    1 : ('Email', 'test.user@gmail.com' ), 
    2 : ('Address', 'new york'),
    3 : ('Notes', 'this is a dummy form'), 
    4 : ('Mobile Phone', '57234985734'),
    5 : ('Work Fax', '5432578943'), 
    6 : ('Work Phone', '32465765765') 
    }
    
    politetitles = {
    1 : ('Mr' ), 
    2 : ('Ms'),
    3 : ('Mrs'), 
    4 : ('Sir'),
    }
    
    class NotifyPropertyChangedBase(INotifyPropertyChanged):
        """INotifyProperty Helper"""
        PropertyChanged = None
        def __init__(self):
            (self.PropertyChanged, self._propertyChangedCaller) = pyevent.make_event()
    
        def add_PropertyChanged(self, value):
            if self.PropertyChanged is not None: 
                self.PropertyChanged += value
    
        def remove_PropertyChanged(self, value):
            if self.PropertyChanged is not None: 
                self.PropertyChanged -= value
    
        def OnPropertyChanged(self, propertyName):
                if self.PropertyChanged is not None: 
                    self._propertyChangedCaller(self, PropertyChangedEventArgs(propertyName))
    
    
    class myListEntry(NotifyPropertyChangedBase):
    
    @property
    def lvalue(self):
        return self._lvalue
    
    @lvalue.setter
    def lvalue(self, value):
        self._lvalue = value
        self.OnPropertyChanged("lvalue")
    
    @property
    def lproperty(self):
        return self._lproperty
    
    @lproperty.setter
    def lproperty(self, value):
        self._lproperty = value
        self.OnPropertyChanged("lproperty")
    
    
    window = Window1()
    
    #print window
    app = Application()
    
    combo = ComboBox()
    titleitems = politetitles.items()
    for key, data in titleitems:
        item = ComboBoxItem()
        item.Content = data
        item.FontSize = 8
        combo.Items.Add(item)
    window.comboBox1.ItemsSource = combo.Items
    
    
    listitems = entries.items()
    listb = ObservableCollection[myListEntry]()
    for key, data in listitems:
        item = ListBoxItem()
        lineitem = myListEntry()
        lineitem.lproperty=data[0]
        lineitem.lvalue=data[1]
        listb.Add(lineitem)
    window.listBox1.ItemsSource = listb
    print listb
    app.Run(window)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have XAML similar to this: <ListBox ItemsSource={Binding SearchCriteria, Source={StaticResource model}} SelectionChanged=cboSearchCriterionType_SelectionChanged> <ListBox.ItemTemplate> <DataTemplate>
I have this ListBox (ComboBox) on GWT : final ListBox category_2=new ListBox(); category_2.setStyleName(article_combo); category_2.addItem(----------,
i have ListBox on my xaml page called MainListBox. i can get index that
I have a ListBox with an ItemTemplate consisting of a TextBlock and a ComboBox
I have a listbox defined in XAML as: <ListBox x:Name=directoryList MinHeight=100 Grid.Row=0 ItemsSource={Binding Path=SelectedDirectories}/>
I was trying to create a custom combobox that inherited from ComboBox, but I've
I have a combobox of Names. There can be person with similar name. Now
Scenario: I have a list table being populated from a combobox. That list table
I have a listbox that you can select users in. To the left of
I have a ListBox with a DataTemplate that looks like this: <ListBox Name=listBox> <ListBox.ItemTemplate>

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.