1

Well, I have a listbox and I bind it with an itemsource:

<ScrollViewer>
<ListBox Name="servicesGroupList" Height="574" Width="408" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Padding="5,0,5,0" Text="{Binding serviceName}" FontSize="20" />
<TextBlock Padding="5,0,5,0" Text="{Binding serviceDesc}" FontSize="10" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>

And I have code behind:

public ObservableCollection<ServiceInfoDTO> dynamicServicesList = new ObservableCollection<ServiceInfoDTO>();
public MainPage()
    {
        this.DataContext = this.dynamicServicesList;
        InitializeComponent();
    }

And also my class is:

public class ServiceInfoDTO
{
    public string serviceName;
    public string serviceDesc;
}

The class is declared in ServiceInfoDTO.cs

When I start the application, I see nothing, I guess the binding is wrong... I tested SO MUCH different methods, and I came here, please help me :)


MANY THANKS TO Alaa Masoud! I guess, this post is a simpliest method to implement the binding and will be very helpful for newbies, I didn't find such post in Internet.

4

1 回答 1

1

Make a get accessor for your properties..

public class ServiceInfoDTO {
  public string serviceName { get; set; }
  public string serviceDesc { get; set; }
}
于 2013-05-29T08:44:04.457 回答