Nel seguente codice, dico al ComboBox per utilizzare il DataTemplate denominato CustomerTemplate assegnando l'attributo ItemTemplate.Come posso ottenere StackPanel per utilizzare un ItemTemplate?
StackPanel, tuttavia, non ha un attributo ItemTemplate.
Come posso ottenere che StackPanel utilizzi anche 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>
perfetta, un altro controllo utile strisciato dalla lavorazione del legno, grazie –
Upvote per il commento Clippy :) – Flater