Récupérer item.Tag dans un DataTemplate
Bonjour,
Je voudrais récupérer la valeur des item.Tag d'un ListBox en cliquan sur l'item:
XAML:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<Window.Resources>
<DataTemplate x:Key="listBoxItem">
<StackPanel Margin="3">
<StackPanel>
<ListBoxItem Tag="{Binding Path=Tag}">
<StackPanel Width="Auto">
<Image Height="16" Source="images/movies_24x24.png" />
<TextBlock Text="{Binding Path=Content}" Width="Auto" />
</StackPanel>
</ListBoxItem>
</StackPanel>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ListBox Name="ListBox1" ItemTemplate="{StaticResource listBoxItem}" Width="214" HorizontalAlignment="Left" Margin="14,116,0,44" BorderThickness="1,1,1,1" />
</Grid> |
J'ajoute les item (Binding):
VB
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
'cree les objets
Dim obj As New cls_film_search
Dim mov As cls_movie_tags
Dim i As Integer = 0
'pour chaque resultat
Dim itemlist As New List(New ListItem)
Dim lst As New List(Of items)
For Each mov In obj.get_propositions(Me.TextBox1.Text)
i = i + 1
lst.Add(New items(mov.title.Replace(" ", " "), mov.num))
'Me.BackgroundWorker1.ReportProgress(i, elt)
Next
Me.ListBox1.ItemsSource = lst
End Sub |
Je veux récupérer le Tag de l'item sélectionner:
VB
Code:
1 2 3 4 5 6 7 8 9 10
|
Private Sub ListBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles ListBox1.MouseDoubleClick
Dim lst As New ListBoxItem
lst = Me.ListBox1.ItemContainerGenerator.ContainerFromIndex(Me.ListBox1.SelectedIndex)
MsgBox(lst.Tag.ToString())
End Sub |
Ici list.Tag.ToString() est null :cry: Pourquoi?
Merci, Olivier.