Bonjour,

Je m'initie au DataTemplate. Ici c'est une listBox avec des checkBox. J'ai trouvé pour associer un XML pour mon test, plus tard je lirai un XML depuis le C# au lieu de faire comme ici un Binding... :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<Window xmlns:my="clr-namespace:WpfApplication6"  x:Class="WpfApplication6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <DataTemplate x:Key="listBoxTemplate">
            <ListBoxItem Background="LightSlateGray" Foreground="Orange"
             FontFamily="Georgia" FontSize="14">
                <CheckBox Name="CoffieCheckBox" >
                    <StackPanel Orientation="Horizontal" >
                        <TextBlock Text="{Binding XPath=Name}"  />
                    </StackPanel>
                </CheckBox>
            </ListBoxItem>
        </DataTemplate>
    </Window.Resources>
 
    <Grid>      
	<ListBox  Name="listBox2"  Foreground="Red" 
		FontFamily="Verdana" FontSize="12" FontWeight="Bold" Margin="247,64,89,99"
		ItemsSource="{Binding}"
		ItemTemplate="{StaticResource listBoxTemplate}"
		IsSynchronizedWithCurrentItem="True" />
    </Grid>
</Window>
Là où j'ai du mal c'est d'associer un évènement lorsqu'un utilisateur cliquera sur un Item ?