简体   繁体   中英

Populating a ListBox from database

I am using Entity Framework to retrieve records from the database. My user control page crashes every time I run it, but after I comment out the lines in BindLstBox method; my user control page runs well. Is there anything wrong with this code? (DAOActivity is a class file which have CRUD codes in it. I suppose there is nothing wrong there.) It shows this error when i try to run :

'The invocation of the constructor on type 'iStellar.home' that matches the specified binding constraints threw an exception.' Line number '5' and line position '14'.

Heres the screenshot of the error :

在此处输入图片说明

DAO.DAOActivity daoActivity = new DAO.DAOActivity();

public home()
{
    InitializeComponent();
    BindListBox();
}

public void BindListBox()
{
    listBox1.ItemsSource = daoActivity.GetAll();
    listBox1.DisplayMemberPath = "ActivityName";
    listBox1.SelectedValuePath = "ActivityID";           
}

My XAML :

  <ListBox Height="534" HorizontalAlignment="Left" Margin="218,415,0,0"
           Name="listBox1" VerticalAlignment="Top" Width="512" />
 Application.Current.Dispatcher.BeginInvoke(
         DispatcherPriority.Background,
            new Action(() =>
            {
                listBox1.ItemsSource = daoActivity.GetAll();
                listBox1.DisplayMemberPath = "ActivityName";
                listBox1.SelectedValuePath = "ActivityID";
            }));

I hope this will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM