|
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:
Str=Form1.TextBox1.Text
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:
Module:
Public WindowBuffer As New Window1
Window1.xaml.vb:
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
WindowBuffer.Close()
End
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
Control.Focus()
Exit For
End If
Next
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.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010
|
|
 |
|