Welcome Guest!
 VB Helper Q & A
 Previous Message All Messages Next Message 
WPF reference and collection  Jamil Youcef
 Dec 16, 2009 12:54 PST 

1/ In windows Forms, when we want to call a Control in the form from Module we refer to it by:
Form. Control
For example if we want assign the Text of a TextBox to a String variable from Module:
This is not working in WPF, I had to define in code in Module level as Public a Window As Window1, set it to be equal to Window1 in Window1_Loaded and close it in Window1_Close, then I could use it to pick up data from Text boxes in Window1.
Here is the code:
Public WindowBuffer As New Window1

Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        WindowBuffer = Me

Private Sub Window1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Closed
    End Sub

2/ I was surprised when I noticed that TabIndex of the text boxes in Window1 was 2147483647
I set them from 0 to the number of text boxes I have increasing by 1, in order to use the For Each statement to move the focus from one TextBox to the other on Key.Enter. Here again I had to define a Collection to which I added all my text boxes then I could use this :

Private Sub Text_GotFocus(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles TxtGrade.GotFocus, TxtPort.GotFocus, TxtRef.GotFocus, TxtVessel.GotFocus
        TextBoxIndex = sender.tabindex
    End Sub

    Private Sub Txt(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles TxtVessel.KeyDown, TxtGrade.KeyDown, TxtPort.KeyDown
        If e.Key = Key.Enter Then
            For Each Control As TextBox In TextBoxCollection
                If Control.TabIndex = TextBoxIndex + 1 Then
                    Exit For
                End If
        End If
    End Sub

I want to understand why is it this way in WPF or if I am wrong in something, please tell me?
I am trying to think in WPF way when I am working with WPF and not in Windows forms way.

Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you.
 Previous Message All Messages Next Message 
  Check It Out!

  Topica Channels
 Best of Topica
 Art & Design
 Books, Movies & TV
 Food & Drink
 Health & Fitness
 News & Information
 Personal Finance
 Personal Technology
 Small Business
 Travel & Leisure
 Women & Family

  Start Your Own List!
Email lists are great for debating issues or publishing your views.
Start a List Today!

© 2001 Topica Inc. TFMB
Concerned about privacy? Topica is TrustE certified.
See our Privacy Policy.