-1
그래서 간단한 데이터 바인딩 연습 프로젝트를 코딩했지만 조금 문제가 있습니다. ListBox에 데이터 바인딩 된 ObservableCollection이 있습니다. 프로그램을 실행하면 처음에는 ListBox에 아무 것도없는 것 같지만 마우스를 가져 가면 ObservableCollections에서와 동일한 항목 수의 윤곽을 볼 수 있지만 아무것도 표시되지 않습니다. 다음은 내 코드입니다 :ListBox 항목이 표시되지 않습니다.
XAML :
<ListBox Margin="0, 40, 0, 0" x:Name="lb1" ScrollViewer.CanContentScroll="True">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock DockPanel.Dock="Left" x:Name="_age" Text="{Binding Path=Age}"/>
<TextBlock DockPanel.Dock="Right" x:Name="_cash" Text="{Binding Path=Cash}" />
<TextBlock DockPanel.Dock="Top" x:Name="_name" Text="{Binding Path=FullName}"/>
<TextBlock DockPanel.Dock="Top" x:Name="_gender" Text="{Binding Path=Gender}"/>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
숨김 코드 :
public class Person{
public Person(string _FullName, int _Age, string _Gender, string _AboutMe, decimal _Cash)
{
this.FullName = _FullName;
this.Age = _Age;
this.Gender = _Gender;
this.AboutMe = _AboutMe;
this.Cash = _Cash;
}
public string FullName;
public int Age;
public string Gender;
public string AboutMe;
public decimal Cash;
}
public partial class MainWindow : Window
{
public ObservableCollection<Person>People = new ObservableCollection<Person>();
public MainWindow()
{
People.Add(new Person("John Doe", 35, "M", "My name is John Doe", 1500));
People.Add(new Person("Sarah Maine", 28, "F", "My name is Sarah Maine", 2150));
People.Add(new Person("George Smith", 65, "M", "My name is George Smith", 4999));
People.Add(new Person("Rachel Ramsey", 46, "F", "My name is Rachel Ramsey", 3199));
People.Add(new Person("Rachel Ramsey", 46, "F", "My name is Rachel Ramsey", 3199));
InitializeComponent();
lb1.ItemsSource = People;
}
}
어떤 아이디어? 감사합니다
는 "수"로 공공 재산 할 필요가
INotifyPropertyChanged
을 구현하기 위해 고려 – Paparazzi