Thank you for this mind twisting question Gaurav. Unfortunately it looks like I am a little bit too late, so the easiest were already suggested. Please see my solution below. As you can see it doesn't utilise any of VB .NET features used in the previous answers. It's not the easiest, not the most straightforward way and not the best design, however it will do the job and completely satisfy the requirements of the question:
XAML
<src:MyTextBox x:Name="TextBlock1" Width="100"/>
<src:MyTextBox x:Name="TextBlock2" Width="100"/>
<src:MyTextBox x:Name="TextBlock3" Width="100"/>
<src:MyTextBox x:Name="TextBlock4" Width="100"/>
<src:MyTextBox x:Name="TextBlock5" Width="100"/>
<src:MyTextBox x:Name="TextBlock6" Width="100"/>
<src:MyTextBox x:Name="TextBlock7" Width="100"/>
You also need to add attribute xmlns:src="clr-namespace:[Project Name]" to your Window tag
Code
Public Class MyTextBox
Inherits TextBox Public
dependentTextBox As MyTextBox
Public Overloads Property Text As String
Get
Return MyBase.Text
End Get
Set(ByVal value As String)
MyBase.Text = value
If Not IsNothing(dependentTextBox) Then
dependentTextBox.Text = value
End If
End Set
End Property
End Class
Class MainWindow
Public Sub New()
InitializeComponent()
TextBlock6.dependentTextBox = TextBlock1
TextBlock5.dependentTextBox = TextBlock2
TextBlock1.dependentTextBox = TextBlock3
TextBlock2.dependentTextBox = TextBlock4
End Sub
... then the rest of MainWindow class provided in the question
Replied on Mar 17 2011 10:20PM
.