Bonjour,
je suis maintenant entrain de développer ma première application en WPF et j'ai besion d'afficher une ListBox des UserControl à gauche et lorsque je clique sur un ListBoxItem , il faut que le UserControl qui se trouve dans cet ListBoxItem s'affiche à droite en grand format. je veux savoir est ce que je doit utiliser un StackPanel ou un ContentPresenter pour afficher le UserControl à droite et comment faire le binding .Bon j'ai beaucoup essayé mais toujours il ne marche pas , voiçi mon code
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
<Window x:Class="MyWpfTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:model1="clr-namespace:MyWpfControlLibrary;assembly=MyWpfControlLibrary"
        Title="MainWindow" Height="677" Width="1433">
    <Grid>
 
        <ListBox x:Name="list" Margin="0,0,942,0">
            <ListBoxItem  IsSelected="True" >
                <model1:UserControl1 UserControlTitle="Title"
                                     UserControlShortTitle="ShortTitle"
                                     UserControlTel="00 00 00 00"
                                     UserControlGSM="00 00 00 00"
                                     UserControlAdresse="Adresse"
                                     Visibility="Visible"
                                     x:Name="customModel1" Width="434" />
            </ListBoxItem>
            <ListBoxItem >
                <model1:UserControl2 UserControlTitle="Title"
                                     UserControlShortTitle="ShortTitle"
                                     UserControlTel="00 00 00 00"
                                     UserControlGSM="00 00 00 00"
                                     UserControlAdresse="Adresse"
                                     Visibility="Visible"
                                     x:Name="customModel2"/>
 
            </ListBoxItem>
            <ListBoxItem >
                <model1:UserControl3 UserControlTitle="Title"
                                     UserControlShortTitle="ShortTitle"
                                     UserControlTel="00 00 00 00"
                                     UserControlGSM="00 00 00 00"
                                     UserControlAdresse="Adresse"
                                     Visibility="Visible"
                                     x:Name="customModel3"/>
            </ListBoxItem>
            <ListBoxItem >
                <model1:UserControl4 UserControlTitle="Title"
                                     UserControlShortTitle="ShortTitle"
                                     UserControlTel="00 00 00 00"
                                     UserControlGSM="00 00 00 00"
                                     UserControlAdresse="Adresse"
                                     Visibility="Visible"
                                     x:Name="customModel4"/>
            </ListBoxItem>
            <ListBoxItem >
                <model1:UserControl5 UserControlTitle="Title"
                                     UserControlShortTitle="ShortTitle"
                                     UserControlTel="00 00 00 00"
                                     UserControlGSM="00 00 00 00"
                                     UserControlAdresse="Adresse"
                                     Visibility="Visible"
                                     x:Name="customModel5"/>
            </ListBoxItem>
        </ListBox>
        <StackPanel DataContext="{Binding ElementName=list, Path=SelectedItem,Mode=OneWay}">
            <StackPanel.Resources>
                <DataTemplate DataType="{x:Type UserControl}">
                    <model1:UserControl1/>
                </DataTemplate>
                <DataTemplate DataType="{x:Type UserControl}">
                    <model1:UserControl2/>
                </DataTemplate>
                <DataTemplate DataType="{x:Type UserControl}">
                    <model1:UserControl3/>
                </DataTemplate>
                <DataTemplate DataType="{x:Type UserControl}">
                    <model1:UserControl4/>
                </DataTemplate>
                <DataTemplate DataType="{x:Type UserControl}">
                    <model1:UserControl5/>
                </DataTemplate>
            </StackPanel.Resources>
        </StackPanel>
    </Grid>
</Window>
dans cette ligne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
 <StackPanel DataContext="{Binding ElementName=list, Path=SelectedItem,Mode=OneWay}">
il m'affiche une exception: XamlParseException
voiçi les détails de cette exception :
'La propriété Set 'System.Windows.ResourceDictionary.DeferrableContent' a levé une exception.'
SVP comment je peut corriger ce problème et est ce que quelqu'un peut me donner une explication ou un lien utile pour comprendre la balise <DataTemplate> </DataTemplate>