错误System.Data.Entity.DynamicProxies作为WPF MVVM中ListBox中的数据[已解决]
问题描述:
嗯,我知道*中存在与此主题相关的问题,这些解决方案不幸并没有帮助我,所以我必须问问它再来一次。感谢您的任何帮助。 我有ListBox,它必须从实体框架代码第一个数据库显示数据。所以我对这个任务的代码:错误System.Data.Entity.DynamicProxies作为WPF MVVM中ListBox中的数据[已解决]
<ListBox Grid.Column="0"
ItemsSource="{Binding PersonCollection}"
SelectedItem="{Binding ThePerson, Mode=TwoWay}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type vm:EmployeeViewModel}">
<StackPanel Orientation="Horizontal">
<TextBlock Padding="2">
<TextBlock.Text>
<MultiBinding StringFormat=" {0} {1} {2}">
<Binding Path="ThePerson.Surname"/>
<Binding Path="ThePerson.FirstName"/>
<Binding Path="ThePerson.MidleName"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</DataTemplate>
</ItemsControl.Resources>
</ListBox>
我的视图模型看起来像:
public EmployeeViewModel()
{
ThePerson = new Person();
_perlog = new PersonLogic();
PersonCollection = new ObservableCollection<Person>(_perlog.Get());
}
凡ThePerson和PersonCollection已经OnThePropertyChanged() 守则PesonLogic从表中显示的数据:
internal IEnumerable<Person> Get()
{
return _dbContext.Persons.ToList();
}
所有此代码通过Error System.Data.Entity.DynamicProxies。 你能帮忙解决吗?我做错了什么? 感谢任何帮助!
UPD我通过替换来解决这个问题。其结果是它单曲在适当的方式工作
答
变化如下因素代码: <ItemsControl.Resources> <DataTemplate DataType="{x:Type vm:EmployeeViewModel}">
要 <ListBox.ItemTemplate> <DataTemplate>
数据类型= “{X:类型VM:EmployeeViewModel}”>应该写在代码在
之后