Bonjour,
je suis débutant sur Windows phone et j'ai un peu du mal à comprendre la liaison de donnée surtout dans le cas qui est le mien en fait.
A ce jour mon appli se présente en un ensemble de vue que j'aimerai relier à des classes qui sont mes ViewModels.
Voici la ViewModel Personne (simplifiée):
Je souhaite relier ces données à ma page xaml...J'aimerai le faire depuis la page xaml même, en référançant la classe Personne...Je ne veux pas le faire en définissant le DataContext dans ma classe.
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 class Personne : INotifyPropertyChanged { public string Id {get; set;} public string DisplayName {get; set;} public string FamilyName {get; set;} public string GivenName { get; set; } public string Email { get; set; } public string FixedLineNumber { get; set; } public string FixedLineShortNumber { get; set; } public string MobilePhoneNumber { get; set; } public Personne() { } public Personne(string xml, TypePersonne typePersonne) { if(string.IsNullOrEmpty(xml)) return; XElement xResultat = XElement.Parse(xml); this.Email = xResultat.Element("Mail").Value; this.MobilePhoneNumber = xResultat.Element("NumMobile").Value; this.DisplayName = xResultat.Element("NomAffichage").Value; this.FamilyName = xResultat.Element("Nom").Value; this.GivenName = xResultat.Element("Prenom").Value; this.Id = xResultat.Element("Matricule").Value; this.FixedLineNumber = xResultat.Element("NumFixe").Value; } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (null != handler) { handler(this, new PropertyChangedEventArgs(propertyName)); } }
Voci mon 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 <phone:PhoneApplicationPage x:Class="AnnuaireBytel.Views.DetailPers" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="728" xmlns:local="clr-namespace:AnnuaireBytel.ViewModels" >
J'aimerai dans l'idéal lié globalement mon xaml à ma classe Personne(ou plus justement à une instance) et après j'aurai qu'à binder sur les propriétés qui m'intéresse pour chaque élément dans ma vue...
Qu'est ce que vous me conseillez ?
Merci d'avance,
Partager