J'ai un problème de binding que je n'avais pas avec la beta 1:
J'ai créé une classe basique :
ma page 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 using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace SimpleBinding { public class Personnes { public string Prenom { get; set; } public string Nom { get; set; } public int Age { get; set; } } }
puis mon code-behind :
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 <UserControl x:Class="SimpleBinding.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300"> <Grid x:Name="LayoutRoot" Background="White"> <ListBox x:Name="lbPersonnes"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="Prenom"/> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid> </UserControl>
Lorsque je lance l'application j'ai une listebox vide alors que si je remplace ma listbox par une textbox ca fonctionne ???
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 using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace SimpleBinding { public partial class Page : UserControl { public Page() { InitializeComponent(); this.Loaded += new RoutedEventHandler(Page_Loaded); } void Page_Loaded(object sender, RoutedEventArgs e) { Personnes p = new Personnes { Prenom = "Anton", Nom = "Dvorak", Age = 25 }; LayoutRoot.DataContext = p; } } }
Merci de votre aide






Répondre avec citation



Pas de questions techniques par MP ! Le forum est là pour ça...




Partager