Bonjour à tous,
Je viens de faire quelques petits tests avec WPF chez moi pour le plaisir (si si promis :p !) et j'ai obtenu quelque chose qui me paraît étrange...
En fait, je crée une simple listebox dont je binde l'itemssource sur une ObservableCollection. Jusque là rien de bien transcendantal...
Tout fonctionne bien, les éléments s'ajoutent bien visuellement. Coup de folie, je décide de sélectionner une élément et là c'est le drame, sur certains cliques deux éléments sont sélectionnés en même temps. Je n'avais jamais eu ce comportement à mon travail.
Cependant mon poste de travail d'entreprise est sous XP et chez moi je suis sous Seven...je me demande donc cela n'a pas un lien...J'ai même recompiler mon projet (qui était initialement compilé via le framework 4.0) en 3.5 mais le résultat est le même.
Je vous livre mon code qui est somme toute très simple...
Mon code XAML :
et mon code behind :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <Window x:Class="TestListBox.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"> <StackPanel> <ListBox ItemsSource="{Binding Source}" SelectionMode="Single" Height="120"/> </StackPanel> </Window>
Quelqu'un aurait-il déjà rencontré ce problème ?
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 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Collections.ObjectModel; using System.ComponentModel; namespace TestListBox { /// <summary> /// Logique d'interaction pour MainWindow.xaml /// </summary> public partial class MainWindow : Window, INotifyPropertyChanged { public MainWindow() { source = new ObservableCollection<string>(); source.Add("a"); source.Add("b"); source.Add("c"); source.Add("a"); source.Add("a"); DataContext = this; InitializeComponent(); } private void OnPropertyChanged(string info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } private ObservableCollection<string> source; public ObservableCollection<string> Source { get { return source; } set { source = value; OnPropertyChanged("Source"); } } public event PropertyChangedEventHandler PropertyChanged; } }
Merci d'avance![]()
Partager