Bonjours !!!
Je suis novice dans le domaine, et je suis entrain de travailler sur un projet, et pour ma classe principal j'utilise l'INotifyPropertyChanged pour attacher un evenement au changement de mes variables.
J'ai une classe "Contexte", qui contient la variable a afficher:
Et ma classe MainWindow de la fenêtre principale:
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 public class Contexte : MainWindow { private string noms; public string Noms { get { return noms; } set { if (value == noms) return; noms = value; NotifyPropertyChanged("Noms"); } } }
Et le code XAML de MainWindow
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 public partial class MainWindow : Window, INotifyPropertyChanged { private static Contexte contexte; int index = 0; public MainWindow() { InitializeComponent(); } private void window_Loaded(object sender, RoutedEventArgs e) { contexte = new Contexte { Noms = "Alpha PREMIER" }; DataContext = contexte; } private void buttonUpdate_Click(object sender, RoutedEventArgs e) { contexte.Noms = "Julien DUBOIS"; } public void updateView() { TextBlock_Titre.Text = "Profil de JULIEN"; } public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged(string nomPropriete) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(nomPropriete)); updateView(); } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <Grid> <StackPanel HorizontalAlignment="Left" Margin="10,10,0,10" Width="200"> <TextBlock name="TextBlock_Titre" Height="25"/> <TextBlock Text="{Binding Noms}" Height="25"/> </StackPanel> <TextBox Name="textBox_index" HorizontalAlignment="Left" Height="23" Margin="215,10,0,0" Text="0" VerticalAlignment="Top" Width="100"/> <Button Content="Update" Click="buttonUpdate_Click" HorizontalAlignment="Left" Margin="215,38,0,0" VerticalAlignment="Top" Width="100"/> </Grid>
Le problème est qu'après clique sur le bouton "Update", l'interface est automatiquement mise à jours, mais le titre (TextBlock_Titre) ne change toujours pas.
Merci++ pour votre aide![]()
Partager