Bonjour,

Mon application me retourne l'exception suivante :
Additional information: 'System.Windows.Data.BindingExpression' value cannot be assigned to property 'ItemsSource' of object 'System.Windows.Controls.ComboBox'. Dispatcher processing has been suspended, but messages are still being processed. Error at object 'System.Windows.Data.Binding' in markup file 'MetaDataManagerControl;component/metadatamanagerview.xaml'.
Mon application possede 2 listbox. La premiere me permet de selectionner un element principal. La seconde, affiche la description associé à cet element dans plusieurs langues.
Il existe egalement un bouton qui me permet d'ajouter une nouvelle description à mon element dans de nouvelles langues.

Lorsque l'on clique sur ce bouton, j'ajoute un nouveau listboxitem a ma seconde listbox. Cet item contient une combobox que j'alimente avec le contenu d'un fichier Xml contenant les codes de langues à utiliser ( fr-FR, en-GB, en-US, etc).

si je valide mes modifications, tout fonctionne parfaitement, ma base et bien mise a jour et mon interface fait ce quelle doit faire.
Malheureusement, des que je reitere une seconde fois cette operation, j'ai cette exception.

Cela semble lié au binding de la combobox.

je met ci-dessous les codes associé a l'item template ainsi qu'au 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
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
 
 <XmlDataProvider x:Key="LanguagesProvider" Source="Languages.xml" XPath="/Languages"  />
        <CollectionViewSource x:Key="SortedLanguagesView" Source="{Binding Source={StaticResource LanguagesProvider}, XPath=Language}">
            <CollectionViewSource.SortDescriptions >
                <cm:SortDescription PropertyName="@title" Direction="Ascending" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
 
<DataTemplate x:Key="mEditableLocalizedDataTemplate">
 
            <Grid Background="Transparent" >
                <Border BorderBrush="{StaticResource ML_GradientBrush}" BorderThickness="4" CornerRadius="10,10,10,10" Background="{StaticResource ML_DarkBlue}" Margin="5,5,5,5" >
 
                    <Grid Background="Transparent" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="25" />
                            <ColumnDefinition Width="30*" />
                            <ColumnDefinition Width="30*" />
                            <ColumnDefinition Width="30*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
 
                        <TextBlock Grid.Column="1" Grid.Row="0" Margin="10,5,0,0" >Language</TextBlock>
                        <ComboBox Name="mComboLanguages"  SelectionChanged="mComboLanguages_SelectionChanged" Grid.Column="2" Grid.Row="0" Margin="5,5,10,5" Width="150"   ItemsSource="{Binding Source={StaticResource SortedLanguagesView}}"  >
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding XPath=@title}" />
                                        <TextBlock Text=" (" />
                                        <TextBlock Text="{Binding XPath=@code}" />
                                        <TextBlock Text=")" />
                                    </StackPanel>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
 
                        <TextBlock  Margin="10,5,0,0" Grid.Column="1" Grid.Row="1">Property A</TextBlock>
                        <TextBox  Style="{StaticResource TextBoxStyle}"  Grid.Column="2" Grid.Row="1" Background="{DynamicResource ML_LightBlue}" Text="{Binding Path=PropertyA}" Margin="5,5,10,5" ></TextBox>
 
                        <TextBlock Margin="10,5,0,0" Grid.Column="1" Grid.Row="3" >Property B</TextBlock>
                        <TextBox Style="{StaticResource TextBoxStyle}" Grid.Column="2" Grid.Row="3" Text="{Binding Path=PropertyB}" Margin="5,5,10,5" ></TextBox>
 
                        <TextBlock Margin="10,5,0,0" Grid.Column="1" Grid.Row="2" >Property C</TextBlock>
                        <TextBox Style="{StaticResource TextBoxStyle}" Grid.Column="2"  Grid.Row="2" Text="{Binding Path=Property C}" Margin="5,5,10,5" AcceptsReturn="True" ></TextBox>
 
                        <StackPanel Grid.Row="4" Grid.Column="2"  Orientation="Horizontal"  HorizontalAlignment="Right" >
                            <Image Source="/MetaDataManagerControl;component/Resources/database_remove.ico" Height="15" ToolTip="Deny changes" Margin="0,0,0,10" Style="{StaticResource ML_ImageStyle}" MouseLeftButtonDown="onCancelNewLanguage" />
                            <Image Source="/MetaDataManagerControl;component/Resources/database_accept.ico" Height="15" ToolTip="Accept changes" Margin="40,0,40,10" Style="{StaticResource ML_ImageStyle}" MouseLeftButtonDown="onValidateNewLanguage" />
                        </StackPanel>
 
                    </Grid>
                </Border>
            </Grid>
        </DataTemplate>
Petite remarque en passant, dans la methode mComboLanguages_SelectionChanged, je recupere la valeur code de langue (ex: fr-FR) resultant de la selection de la combobox pour l'affecter à une propriété de l'objet correspondant a ce même listboxitem. N'y a t'il pas une meilleure methode ?

Merci de vos conseils.