LstbClients라는 ListBox에서 각 Label 또는 TextBlock에 Name 및 Phonenumber를 표시하려면 (필자에게 상관 없음) 이전에 ComboBox를 사용하여 DataBinded를 사용하고 작업했는지 확인합니다 꽤 좋긴하지만 어떤 이유로이 ListBox에서 작동하지 않습니다.목록 상자에 특정 개체의 값이 표시되지 않음 (데이터 바인딩)
이것은 XAML 코드입니다. 이 목록 상자의 레이블 만 보여 않습니다 어떤 이상한 이유로
public class Client
{
public int ID;
public string Lastname;
public string Name;
public string Streetname;
public string Postcode;
public string City;
public int Phonenumber;
public string Email;
public DateTime CreationDate;
public DateTime BirthDate;
public Client(int id, string lastname, string name, DateTime birthDate, string streetname, string postcode, string city, int phonenumber, string email, DateTime creationDate)
{
this.ID = id;
this.Lastname = lastname;
this.Name = name;
this.Streetname = streetname;
this.Postcode = postcode;
this.City = city;
this.Phonenumber = phonenumber;
this.Email = email;
this.CreationDate = creationDate;
this.BirthDate = birthDate;
}
}
Client.cs
뒤에 코드//clients is a filled ObservableCollection<client>
lstbClients.ItemsSource = clients;
":
<ListBox x:Name="lstbClients"
Height="300"
Grid.Row="0" Grid.Column="0"
Style="{StaticResource inputControls}"
ItemsSource="{Binding clients}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Name}"/>
<Label Content=", "/>
<Label Content="{Binding Phonenumber}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
이 뒤에 코드는 "이름과 전화 번호를 무시하고 예를 들어 WPF 응용 프로그램에서 ListBox를 열면 모든 데이터에 ... ListBox가 데이터를 가져 오지만 레이블에 표시하지 않으려 고합니다. lstbClients, 그래서 어떤 레이블에 어떤 데이터가 포함되어 있는지 확인할 수는 없습니다.
클라이언트 클래스의 코드를 보여줍니다. 왜 XAML과 코드 숨김에서 ItemsSource를 설정하고 있습니까? –
사이트에 오신 것을 환영합니다! 귀하의 질문에 "나는 초학자입니다."라고 덧붙일 필요가 없습니다. 모두가 초보자 였으므로 걱정하지 마십시오. 프로젝트에 행운을 빌어 요! – dasblinkenlight
XAML이 훌륭하게 보입니다. Observable Collection에 INotifyPropertyChanged를 구현하지 않았다고 추측합니다. Observable Collection 선언을위한 코드를 보여주십시오. 또한 런타임 중에 출력 창을 검사하여 바인딩 오류가 발생하지 않도록하십시오. 그것들은 당신이 당신의 문제를 찾도록 도울 수 있습니다. –