I have a quite simple question:
I have a People property whose type is List< Person > and a Person has a Name and Surname. I want to show the Name on my listBoxPerson and ı want to make bindng operations in code behind -dont want to use ItemsSource property- Here is my code snippet:
Binding userBinding = new Binding();
userBinding.Source =People;
userBinding.Path = new PropertyPath("Person.Name");
listBoxPerson.SetBinding(ContentProperty, userBinding);
and here is my xaml code:
< ListBox Height="303" HorizontalAlignment="Left" Margin="12,108,0,0" Name="listBoxPerson" VerticalAlignment="Top" Width="234" >
< ListBox.Resources >
< ObjectDataProvider x:Key="UserData" ObjectType="local:Person"/ >
< /ListBox.Resources >
< ListBox.ItemTemplate >
< DataTemplate >
< Label Content="{Binding Path=Name}" ></Label >
< /DataTemplate >
< /ListBox.ItemTemplate >
< /ListBox >
this works when I write
listboxPerson.ItemsSource= People;
but there is nobody listed with the first given code. I am confused on how to solve this binding problem, and will be pleased with any help=)