Create ItemTemplate for ListBox in code-beind in WPF
问题 I'm trying to create an ItemTemplate for a ListBox programmatically but it doesn't work. I know in XAML I can have something like: <ListBox x:Name="listbox" BorderThickness="0" Margin="6" Height="400"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Margin="0" Background="Red" Foreground="White" FontSize="18" Text="{Binding}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> But when I'm trying to have the above result programmatically I face a problem which is binding the TextBox