Binding

asprog Messages postés 33 Date d'inscription mercredi 12 novembre 2008 Statut Membre Dernière intervention 26 décembre 2010 - 26 nov. 2008 à 16:10
asprog Messages postés 33 Date d'inscription mercredi 12 novembre 2008 Statut Membre Dernière intervention 26 décembre 2010 - 27 nov. 2008 à 13:53
bonjour je veux faire un binding de la propriété text d'un textbox dans le fichier xaml de l'interface wpf mais ça marche pas et je ne sais pas prq voici le code xaml:
sachant que j'ai créer une classe nommée person dont ses 2 propriétés PersonName et Name et je veux que lorsque j'écris dans le textebox le contenu s'affichera dans le textblock


<Window x:Class="Window1"








xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"






xmlns
:
x
="http://schemas.microsoft.com/winfx/2006/xaml"






xmlns
:
src
="clr-namespace:WpfApplication1"






Title
="Window1"
Height
="300"
Width
="300">

<
Window.Resources
>







<
src
:
Person
x
:
Key
="MonDataSource">





</
src
:
Person
>





</
Window.Resources
>





<
Grid
>





<
Label
>
ecrivez vos noms :
</
Label
>





<
TextBox
>





<
TextBox.Text
>





<
Binding
Source
="{
StaticResource
MonDataSource
}"
Path
="Name"
UpdateSourceTrigger
="PropertyChanged">





</
Binding
>





</
TextBox.Text
>





</
TextBox
>





<
Label
>

le nom que vous avez taper est::






</
Label
>





<
TextBlock



Text
="{
Binding
Source
={
StaticResource
MonDataSource
},
Path
=Name}"
Background
="Beige"
Width
="100"
Height
="20"/>





</
Grid
>

 

4 réponses

ricky84 Messages postés 44 Date d'inscription dimanche 8 septembre 2002 Statut Membre Dernière intervention 13 janvier 2014
26 nov. 2008 à 18:42
Dans ta classe Person, tu dois avoir :

Implements INotifyPropertyChanged

Private

MNom
As
String

Public
Event PropertyChanged
As PropertyChangedEventHandler_
ImplementsINotifyPropertyChanged.PropertyChanged

Private
Sub NotifyPropertyChanged(
ByVal info
As
String)
   
RaiseEvent PropertyChanged(
Me,
New PropertyChangedEventArgs(info))

End
Sub

Public
Property Nom()
As
String
   Get
      Return MNom
   
End
Get
   Set(
ByVal value
As
String)
      MNom = value
      NotifyPropertyChanged(
"Nom")
   
End
Set
End
Property

Maiis BON COURRAGE avec WPF !! Y'a rien de simple ni évident avec cette usine à gaz !
0
asprog Messages postés 33 Date d'inscription mercredi 12 novembre 2008 Statut Membre Dernière intervention 26 décembre 2010
27 nov. 2008 à 10:37
merci beaucoup pour cela
0
asprog Messages postés 33 Date d'inscription mercredi 12 novembre 2008 Statut Membre Dernière intervention 26 décembre 2010
27 nov. 2008 à 11:23
ayayayaya,ma classe ne veut pas implementer l'interface INotifyPropertyChanged il ne connais pas ce nom (type 'INotifyPropertyChanged' non défini) même si j'importe l'espace de nom componentModel.et la même chose pour le type PropertyChangedeventHandler Pouvez vous m'aider?
0
asprog Messages postés 33 Date d'inscription mercredi 12 novembre 2008 Statut Membre Dernière intervention 26 décembre 2010
27 nov. 2008 à 13:53
non,ça y-est ça marche maintenant merci j'ai importé le namespace system.componentModel et ça marche avec moi merci
0
Rejoignez-nous