Bonjour,
J'utilise VS2008 avec C#.
J'ai besoin d'aide pour mon application.
J'aimerai savoir comment se passe le binding avec un richTextBox(rtb).
Si quelqu'un a une idée!!!
Voila, j'ai un rtb dans mon application.
Code xaml :
Code behind C#
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <UserControl.Resources> <ResourceDictionary> <ObjectDataProvider x:Key="odpDescription"/> </ResourceDictionary> </UserControl.Resources> <Grid IsEnabled="{Binding Source={StaticResource odpDescription}}" > <GroupBox Header="Description" Margin="0,4,0,2" Name="gbDescription"> <RichTextBox Height="57" Name="rtbDescription" Width="400" VerticalScrollBarVisibility="Visible"/> </GroupBox> </Grid>
Classe Description
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
48
49
50
51
52
53
54
55
56 public partial class DescriptionControl : UserControl { #region Constructeur public DescriptionControl() { InitializeComponent(); odpDescription = (ObjectDataProvider)this.FindResource("odpDescription); } #endregion #region Membres private ObjectDataProvider odpDescription = null; #endregion #region DependencyProperties public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(Description), typeof(DescriptionControl), new FrameworkPropertyMetadata(new Description(), new PropertyChangedCallback(OnDescriptionChanged))); #endregion #region DependencyPropertiesMethods private static void OnDescriptionChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { DescriptionControl descriptionControl = (DescriptionControl)obj; descriptionControl .OdpDescription = descriptionControl.Description; } #endregion #region Clr Accessors public Description OdpDescription { get { return (odpDescription != null ? (Description)odpDescription.ObjectInstance : null); } set { if (odpDescription != null) odpDescription.ObjectInstance = value; } } public Description Description { get { return ((Description)GetValue(DescriptionProperty)); } set { SetValue(DescriptionProperty, value); } } #endregion }
J'aimerais "binder" le rtb avec l'attribut "commentaire" de type string. J'ai créé le odpDescription pour faire le binding mais après je suis bloqué.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 class Description { private string commentaire; public String Commentaire { get { return commentaire; } set { commentaire = value; } } }
Merci d'avance.
Partager