2017-10-10 12 views
0

このトピックに関連するStackOverflowに質問があることは間違いなく助かりませんでしたので、私はそれを尋ねなければなりませんもう1回。何か助けてくれてありがとう。 私は、エンティティフレームワークのコードの最初のデータベースからのデータを表示する必要があるListBoxを持っています。WPF MVVMのListBoxのデータとしてSystem.Data.Entity.DynamicProxies [解決済み]

<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> 

私のViewModelには次のようになります:テーブルからのデータを表示するための

ThePersonとPersonCollectionがOnThePropertyChangedいる
public EmployeeViewModel() 
     {   
      ThePerson = new Person(); 
      _perlog = new PersonLogic(); 
     PersonCollection = new ObservableCollection<Person>(_perlog.Get()); 
     } 

()PesonLogicで コード:

internal IEnumerable<Person> Get() 
    { 
     return _dbContext.Persons.ToList(); 
    } 
このタスクのだから私のコード

このコードはすべて、エラーSystem.Data.Entity.DynamicProxiesによって生成されます。 解決策をお手伝いできますか?私は間違っている? ご協力いただきありがとうございます。

UPD私はこの問題を次のように置き換えました。結果それ `sは

答えて

0

変更folowingコード適切な方法で動作するように: <ItemsControl.Resources> <DataTemplate DataType="{x:Type vm:EmployeeViewModel}">

<ListBox.ItemTemplate> <DataTemplate>

データ型に= "{X:タイプVM:EmployeeViewModelは}">コードで書かれるべき後ろに

関連する問題