Click event en code behind
Bonjour!
J'ai un window1 avec un listbox personnalisé à l'aide d'un fichier resource dictionary (Template.xaml).
La personnalisation me permet ainsi d'avoir un bouton dans chaque items.
Mon soucis est que je voudrais déclencher un événement en cliquant dessus par "code behind" dans mon fichier Template.xaml.vb.
Par exemple récupérer le selectedindex de ma listbox.
Je vous donne mon code window1 :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="836.583" Width="1040" WindowStyle="None" ResizeMode="NoResize" Left="0" Top="0">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Templates.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Canvas Height="800" Name="Canvas1" Width="1024" >
<ListBox ItemTemplate="{StaticResource listBoxJoueur}" ItemsSource="{Binding Tables[0]}" Canvas.Left="382.118" Canvas.Top="-2.75" Height="641.098" Name="LBox_Joueurs" Width="592.5" FontSize="15" />
</Canvas>
</Window> |
mon code Resource :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="test" >
<!-- LISTBOX JOUEURS -->
<DataTemplate x:Key="listBoxJoueur">
<Border CornerRadius="4"
BorderBrush="Navy"
BorderThickness="1"
Padding="1"
Margin="1"
MinWidth="350" Height="100"
x:Name="ItemBorder">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="LightBlue"/>
<GradientStop Offset="1" Color="AliceBlue"/>
</LinearGradientBrush>
</Border.Background>
<StackPanel>
<DockPanel >
<Image Width="120" Height="90" Source="{Binding Photo}"/>
<TextBlock Text=" "/>
<TextBlock Text="{Binding NomJoueurs}" Foreground="RoyalBlue" FontWeight="Bold" FontSize="15" />
<Button Content="fff" Height="50" Width="100" x:Name="_buttonDeleteGroupe" Click="TonEvent" />
</DockPanel >
<DockPanel>
<TextBlock Text=" "/>
<TextBlock Text="{Binding Photo}" Foreground="RoyalBlue" FontWeight="Bold" FontSize="15" />
</DockPanel>
</StackPanel>
</Border>
</DataTemplate>
</ResourceDictionary> |
Et mon Template.xaml.vb quand je clique sur mon bouton:
Code:
1 2 3 4 5 6 7 8 9 10
|
Class test
Dim a As New JUKEBOX_WPF.Application
Private Sub TonEvent(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
MsgBox("test", MsgBoxStyle.Critical)
' MsgBox("JOUEUR N° : " & LBox_Joueurs.SelectedIndex, MsgBoxStyle.Critical)
End Sub
End Class |
Evidement je n'arrive pas à obtenir l'accès à ma listbox ailleurs que dans Window1...
Si quelqu'un peut m'aider car je ne trouve pas de solution!Même pas dans le livre de Mr Lebrun... ou alors qu'on me donne le numéro de la page ;)