The following code gives me the error (cannot add type Object to Stackpanel).
How can I say .ToString() in XAML?
<Window.Resources> <Style TargetType='{x:Type ListBoxItem}'> <Setter Property='Content'> <Setter.Value> <StackPanel Orientation='Horizontal'> <TextBlock Text='{Binding Path=FirstName}'/> </StackPanel> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <ListBox x:Name='theCustomers'/> </Grid>
binding in code-behind with ADO.NET Entity Framework:
MainEntities db = new MainEntities(); var customers = from c in db.CustomersSet select c; theCustomers.ItemsSource = customers;
You need to set the property
ContentTemplate, notContent.Try:
See this article