Bonjour,
J'ai une classe Data
Cette classe est binder pour communiquer avec un DataGrid :
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 namespace TestDataGridComboBoxTranslate { class Data : INotifyPropertyChanged { private int value; private string type; public int Value { get { return value; } set { this.value = value; OnPropertyChanged("Diametre"); } } public string Type { get { return type; } set { type = value; OnPropertyChanged("Diametre"); } } public Data() { value = 0; type = "default"; } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(String info) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(info)); } } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <Window x:Class="TestDataGridComboBoxTranslate.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"> <Grid> <DataGrid Name="DataGrid" AutoGenerateColumns="False" Height="311" HorizontalAlignment="Left" VerticalAlignment="Top" Width="503"> <DataGrid.Columns> <DataGridTextColumn Header="{StaticResource Value}" Binding="{Binding Type}"></DataGridTextColumn> <DataGridTextColumn Header="{StaticResource Type}" Binding="{Binding Value}"></DataGridTextColumn> </DataGrid.Columns> </DataGrid> </Grid> </Window>Comme vous pouvez le voir, j'utilise un dictionnaire de ressource pour pouvoir effectuer une traduction de l'application de manière dynamique.
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 namespace TestDataGridComboBoxTranslate { /// <summary> /// Logique d'interaction pour MainWindow.xaml /// </summary> public partial class MainWindow : Window { List<Data> listData = new List<Data>(); public MainWindow() { InitializeComponent(); DataGrid.ItemsSource = listData; var data = new Data(); data.Value = 69; data.Type = "Super"; listData.Add(data); } } }
Le code ci-dessus marche, mais j'aimerai avoir pour Data.type un int sélectionné depuis une combo box. Donc il faut que les champs de la combo box se mettent à jour de manière dynamique.
Voici le dictionnaire enfrançaisanglais:
Par une manière très sale (sans bind, sans utilisé le dictionnaire) j'arrive à un comportement presque fonctionnel. Mais cela ne me satisfait pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:lang="clr-namespace:System;assembly=mscorlib"> <lang:String x:Key="Type">Type</lang:String> <lang:String x:Key="Value">Value</lang:String> <lang:String x:Key="Type1">TypeEN1</lang:String> <lang:String x:Key="Type2">TypeEN2</lang:String> <lang:String x:Key="Type3">TypeEN3</lang:String> <lang:String x:Key="Type4">TypeEN4</lang:String> </ResourceDictionary>
J'ai essayè par l'utilisation d'une DataGridComboBoxColumn, DataGridTemplateColumn avec une ComboBox. Mais je n'arrive pas à un résultat correct, car soit le bind ne fonctionnne pas, soit l'application plante, ,soit la traudciton ne se fait pas, soit il ne se passe rien
Donc j'aimerai un peu d'aide, au moins pour rediriger ma recherche sur le bon composant.
Merci
Voici quelque lien utile :
http://bytes.com/topic/c-sharp/answe...n-datagrid-wpf
http://msdn.microsoft.com/fr-fr/library/ms752347.aspx
http://msdn.microsoft.com/fr-fr/libr...vs.100%29.aspx
http://msdn.microsoft.com/fr-fr/libr...=vs.80%29.aspx
http://msdn.microsoft.com/fr-fr/libr...boxcolumn.aspx
Partager