-1
シンプルなデータバインディングの練習プロジェクトをコーディングしましたが、少し問題があります。私はListBoxにデータバインドされたObservableCollectionを持っています。私がプログラムを実行すると、まずListBoxに何もないように見えますが、マウスの上にマウスを置くとObservableCollectionsと同じ数の項目の輪郭を見ることができますが、何も言われません。 は、ここに私のコードです:リストボックスの項目が表示されない
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;
}
}
任意のアイデア?おかげ
を実装することを検討します – Paparazzi