Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to bind two textboxes to a single text property but if I change text of one textbox the source updates and not the other textbox. How can I bind them both.

Here's my code :

 Public Sub New
     DataContext = Me
 End Sub

Private _text As String = "Test string"
  Public Property Text As String
      Get
          Return _text
      End Get
      Set(value As String)
          If Not _text = value Then
              _text = value
              OnPropertyChanged("Text")
          End If
      End Set
  End Property

Here's my xaml:

XML
<TextBox Text="{Binding Text,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,ValidatesOnNotifyDataErrors=True}"/>
            <TextBox Text="{Binding Text,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,ValidatesOnNotifyDataErrors=True}"/>


What I have tried:

I don't know what to do. But I tried to create a dependency property but I afraid that my code would become complicated.
Posted
Updated 29-Sep-19 19:42pm
v2

1 solution

Your property is Text, but you are triggering a PropertyChanged("Temp").

Another possibility... have you set the DataContext of the window?
 
Share this answer
 
Comments
Member 13072933 30-Sep-19 1:42am    
Sorry for that mistake. But still no improvement.
Nelek 3-Oct-19 8:46am    
Have you tried
<textbox text="{Binding Path=Text,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,ValidatesOnNotifyDataErrors=True}">
?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900