Reputation: 1071
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" />
Upvotes: 0
Views: 313
Reputation: 12315
Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background,
new Action(() =>
{
listBox1.ItemsSource = daoActivity.GetAll();
listBox1.DisplayMemberPath = "ActivityName";
listBox1.SelectedValuePath = "ActivityID";
}));
I hope this will help.
Upvotes: 1