En el siguiente código, le digo al ComboBox que use DataTemplate denominado CustomerTemplate asignando su atributo ItemTemplate.¿Cómo puedo hacer que StackPanel use una ItemTemplate?
StackPanel, sin embargo, no tiene un atributo ItemTemplate.
¿Cómo puedo hacer que StackPanel también use CustomerTemplate?
<Window.Resources>
<DataTemplate x:Key="CustomerTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding FirstName}"/>
<TextBlock Text=" "/>
<TextBlock Text="{Binding LastName}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<DockPanel LastChildFill="False" Margin="10">
<ComboBox
x:Name="CustomerList"
ItemTemplate="{StaticResource CustomerTemplate}"
HorizontalAlignment="Left"
DockPanel.Dock="Top"
Width="200"
SelectedItem="{Binding SelectedCustomer, Mode=TwoWay}"
ItemsSource="{Binding Customers}"/>
<StackPanel DataContext="{Binding SelectedCustomer}" Orientation="Horizontal">
<TextBlock Text="Chosen: "/>
<TextBlock Text="{Binding LastName}"/>
</StackPanel>
</DockPanel>
perfecta, otro control útil salió de la nada, gracias –
Upvote por el comentario :) Clippy – Flater