2012-04-28 5 views
0

내가 여기서 변경해야 할 부분을 볼 수 있습니까? AddressTypeClass 항목의 observablecollection을 표시하고 있습니다. 개체 항목이 데이터 대신 목록 상자에 표시됩니다. 디버그 모드에서 객체의 데이터를 볼 수 있습니다.Linq의 ObservableCollection

XAML.CS 파일 :

DataContext MyTableDataContext = new MyTableDataContext(); 
ObservableCollection<AddressTypeClass> theOC = new ObservableCollection<AddressTypeClass>(new MyTableDataContext().AddressTypes.AsEnumerable() 
     .Select(lt => new AddressTypeClass 
     { 
      AddressTypeID = lt.AddressTypeID, 
      AddressType = lt.AddressType, 
     }) 
      .ToList()); 
this.listBox1.ItemsSource = theOC; 

XAML 파일 :

<ListBox Name="listBox1" Margin="8" Height ="200" Width ="150" FontSize="12" Foreground="#FF2F3806" ItemsSource="{Binding AddressType}" IsSynchronizedWithCurrentItem="True" > 
    </ListBox> 
+0

사용자의 ItemsSource는 .xaml과 다른 코드입니다. 코드 뒤에 코드를 설정할 필요는 없지만 .xaml은 "theOC"로 설정해야합니다. 그런 다음 DisplayMemberPath를 AddressType으로 설정하십시오. –

답변

0

당신은 당신의 목록 상자, 예를 들어,에 ItemTemplate을 추가해야합니다

<ListBox Name="listBox1" Margin="8" Height ="200" Width ="150" FontSize="12" Foreground="#FF2F3806" ItemsSource="{Binding AddressType}" IsSynchronizedWithCurrentItem="True" > 
    <ListBox.ItemTemplate> 
    <DataTemplate> 
     <StackPanel> 
     <TextBlock Text="{Binding Path=AddressType}" /> 
     </StackPanel> 
    </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox>