Comment puis-je obtenir StackPanel d'utiliser un ItemTemplate?
Dans le code suivant, je dis la ComboBox à utiliser le DataTemplate appelé CustomerTemplate par l'affectation de ses ItemTemplate attribut.
StackPanel, cependant, n'a pas un ItemTemplate attribut.
Comment puis-je obtenir le StackPanel également l'utilisation du 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>
OriginalL'auteur Edward Tanguay | 2009-06-18
Vous devez vous connecter pour publier un commentaire.
ItemsControl est essentiellement un StackPanel avec un ItemTemplate. Il utilise un StackPanel en interne.
Cependant, il semble que vous essayez d'afficher un seul client, plutôt qu'une liste d'entre eux (que je ressemble à trombine le trombone, n'est-ce pas?). Dans ce cas, vous souhaitez utiliser un ContentControl:
Upvote pour la trombine le trombone commentaire 🙂
"Il semble que vous essayez d'écrire un upvote-réponse digne"
OriginalL'auteur Matt Hamilton