Bonjour,

J'essaye de faire une application WPF contenant une combobox dont les données sont issues d'ironpython. Facile, sans doute, mais je n'y arrive pas malgré de longues recherches.

Ce qui fonctionne :
- avec une listbox, ça fonctionne parfaitement
- avec un combobox, j'arrive à afficher les données que je veux, et je peux sélectionner les lignes souhaitées avec les flèches du clavier.

Ce qui ne fonctionne pas :
- impossible de sélectionner les éléments avec la souri. Lorsque je clique sur la combobox, elle s'ouvre, m'affiche les informations, mais la zone contenant les données n'est pas sélectionnable. Info qui peut avoir son importante : si je ne suis pas en mode "binding" avec des données issues d'ironpython, mais avec des données que je saisis directement dans le xaml, ça fonctionne parfaitement.

Une idée d'où cela vient ?

Ci-dessous mon code :

window1.py :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
import wpf
 
from System.Windows import Window
 
class Window1 (Window):
    def __init__(self):
        wpf.LoadComponent(self, 'Window1.xaml')
WpfApplication3.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
import wpf
from System.Windows import Application, Window
from Window1 import Window1
from System.Windows.Controls import(ComboBox, 
    ComboBoxItem, ListBox, ListBoxItem)
from System.Collections.ObjectModel import *
from System.ComponentModel import *
from System.Windows.Controls import *
import pyevent 
 
 
entries = {
1 : ('Email', 'test.user@gmail.com' ), 
2 : ('Address', 'new york'),
3 : ('Notes', 'this is a dummy form'), 
4 : ('Mobile Phone', '57234985734'),
5 : ('Work Fax', '5432578943'), 
6 : ('Work Phone', '32465765765') 
}
 
politetitles = {
1 : ('Mr' ), 
2 : ('Ms'),
3 : ('Mrs'), 
4 : ('Sir'),
}
 
class NotifyPropertyChangedBase(INotifyPropertyChanged):
    """INotifyProperty Helper"""
    PropertyChanged = None
    def __init__(self):
        (self.PropertyChanged, self._propertyChangedCaller) = pyevent.make_event()
 
    def add_PropertyChanged(self, value):
        if self.PropertyChanged is not None: 
            self.PropertyChanged += value
 
    def remove_PropertyChanged(self, value):
        if self.PropertyChanged is not None: 
            self.PropertyChanged -= value
 
    def OnPropertyChanged(self, propertyName):
            if self.PropertyChanged is not None: 
                self._propertyChangedCaller(self, PropertyChangedEventArgs(propertyName))
 
 
class myListEntry(NotifyPropertyChangedBase):
    @property
    def lvalue(self):
        return self._lvalue
 
    @lvalue.setter
    def lvalue(self, value):
        self._lvalue = value
        self.OnPropertyChanged("lvalue")
 
    @property
    def lproperty(self):
        return self._lproperty
 
    @lproperty.setter
    def lproperty(self, value):
        self._lproperty = value
        self.OnPropertyChanged("lproperty")
 
 
window = Window1()
 
#print window
app = Application()
 
combo = ComboBox()
titleitems = politetitles.items()
for key, data in titleitems:
    item = ComboBoxItem()
    item.Content = data
    item.FontSize = 8
    combo.Items.Add(item)
window.comboBox1.ItemsSource = combo.Items
 
 
listitems = entries.items()
listb = ObservableCollection[myListEntry]()
for key, data in listitems:
    item = ListBoxItem()
    lineitem = myListEntry()
    lineitem.lproperty=data[0]
    lineitem.lvalue=data[1]
    listb.Add(lineitem)
window.listBox1.ItemsSource = listb
print listb
app.Run(window)
Window1.xaml
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
 
<Window 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       Title="WpfApplication3" Height="300" Width="300">
    <Window.Resources>
        <DataTemplate x:Key="DataTemplate1">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="80"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
 
                <TextBlock Text="{Binding Path=lproperty, FallbackValue=Property}"/>
                <TextBlock Text="{Binding Path=lvalue, FallbackValue=Value}" Grid.Column="1" HorizontalAlignment="Right" Margin="0,0,-60,0" Width="360" />
            </Grid>
 
 
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <ComboBox x:Name="comboBox1" HorizontalAlignment="Left" Height="30" Margin="30,25,0,0" VerticalAlignment="Top" Width="230"/>
        <ListBox x:Name="listBox1"
                Grid.Column="0"
                Grid.Row="0"
                VerticalAlignment="Top"
                Margin="0,60,14.6,0"
                Height="202" HorizontalAlignment="Right" Width="249" 
                ItemsSource="{Binding}" ItemTemplate="{DynamicResource DataTemplate1}"/>
    </Grid>
</Window>
Help !