locked
TextBox_TextChanged is not a Member of AppName.Mainpage RRS feed

  • Question

  • In my Windows Store App, being written in VB, I have a file named "MainPage.g.vb" and within a sub named "Connect" there's this series of errors related to the TextChanged events of the dozens of textboxes which my app has. When I comment out these lines, the app will function okay, but the commented-out lines always eventually uncomment themselves. Here is one of the problem sections, if someone can point me what is causing it and how to repair it.

            Public Sub Connect(ByVal connectionId As Integer, ByVal target As Global.System.Object) Implements Global.Windows.UI.Xaml.Markup.IComponentConnector.Connect
                If (connectionId = 1) Then
                    #ExternalSource("..\..\MainPage.xaml",388)
                    AddHandler CType(target, Global.Windows.UI.Xaml.Controls.TextBox).TextChanged, AddressOf Me.TextBox_TextChanged
                    #End ExternalSource

    And then there's a long series of ElseIf's, but each with a different index number of the ExternalSources.

    The error is underlined on the "AddressOf Me.TextBox_TextChanged" and the error correction option says "Generate method stub for TextBox_TextChanged in AppName.MainPage"

    I have dozens of textboxes, and I use the TextChanged event in code, and it works well. But how do I repair these errors in the g.vb file?

    Friday, October 11, 2013 4:10 AM

Answers

  • Hi David,

    the g.vb-file is generated, that's what the "g" in the filename stands for. The file is generated from your MainPage.xaml-file (based on the x:Class-Attribut on the root element and on the Build Action in the Properties-Windows for that file).

    So you shouldn't change the g.vb-file, because it's always regenerated out of the MainPage.xaml-file. Instead you should change your MainPage.xaml-file. On the TextBox-Elements, you've still defined the EventHandlers for the TextChanged-Event like this:

    <TextBox TextChanged="TextBox_TextChanged".../>

    You should remove those TextChanged-Attributes, as you mentioned you're adding Event Handlers in codebehind. Then it'll compile. If you don't remove the TextChanged-Attributes, ensure that the TextBox_TextChanged-Event Handler is defined in the MainPage.xaml.vb-file


    Thomas Claudius Huber

    "If you can´t make your app run faster, make it at least look & feel extremly fast"

    twitter: @thomasclaudiush
    homepage: www.thomasclaudiushuber.com
    author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook

    Friday, October 11, 2013 9:46 AM
  • Hi David,

    Like Thomas says, remove the TextChanged="TextBox_Changed" event from the Xaml. That declares the event to call the TextBox_Changed method. The .g. file is generated from the Xaml and should never be edited by hand.

    Alternately, you can define the MainPage.TextBox_Changed method and use that rather than setting new event handlers in code.

    --Rob

    • Marked as answer by Anne Jing Friday, October 18, 2013 2:31 AM
    Friday, October 11, 2013 2:25 PM
    Moderator

All replies

  • Hi David,

    the g.vb-file is generated, that's what the "g" in the filename stands for. The file is generated from your MainPage.xaml-file (based on the x:Class-Attribut on the root element and on the Build Action in the Properties-Windows for that file).

    So you shouldn't change the g.vb-file, because it's always regenerated out of the MainPage.xaml-file. Instead you should change your MainPage.xaml-file. On the TextBox-Elements, you've still defined the EventHandlers for the TextChanged-Event like this:

    <TextBox TextChanged="TextBox_TextChanged".../>

    You should remove those TextChanged-Attributes, as you mentioned you're adding Event Handlers in codebehind. Then it'll compile. If you don't remove the TextChanged-Attributes, ensure that the TextBox_TextChanged-Event Handler is defined in the MainPage.xaml.vb-file


    Thomas Claudius Huber

    "If you can´t make your app run faster, make it at least look & feel extremly fast"

    twitter: @thomasclaudiush
    homepage: www.thomasclaudiushuber.com
    author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook

    Friday, October 11, 2013 9:46 AM
  • David try doing a rebuild from the build menu. It usually sorts out errors with the generated file for me.
    Friday, October 11, 2013 10:08 AM
  • Thanks for the replies.

    I tried the rebuild menu. A popup says: "This file has been modified outside of the source editor. Do you want to reload it?" and no option selected (Yes/Yes to All/No/No to All) helps to resolve this issue.

    The XAML for one of the TextBoxes shows this, where I see the TextChanged included in the markup:

                <TextBox x:Name="tL1L1" HorizontalAlignment="Left" Margin="0,13,0,0" TextWrapping="Wrap" Text="8" VerticalAlignment="Top" Width="71" FontSize="54" Height="71" RenderTransformOrigin="0.547,0.027" FontFamily="MS Reference Sans Serif" BorderThickness="0" TextChanged="TextBox_TextChanged" Foreground="{StaticResource ProgressBarForegroundThemeBrush}" Padding="18,1,0,0">
                    <TextBox.RenderTransform>
                        <CompositeTransform TranslateX="13"/>
                    </TextBox.RenderTransform>
                </TextBox>

    Not sure if it matters, but I did do a copy/paste to create the textboxes. Regards.


    • Edited by David VB2005 Friday, October 11, 2013 1:57 PM speling
    Friday, October 11, 2013 1:56 PM
  • Hi David,

    Like Thomas says, remove the TextChanged="TextBox_Changed" event from the Xaml. That declares the event to call the TextBox_Changed method. The .g. file is generated from the Xaml and should never be edited by hand.

    Alternately, you can define the MainPage.TextBox_Changed method and use that rather than setting new event handlers in code.

    --Rob

    • Marked as answer by Anne Jing Friday, October 18, 2013 2:31 AM
    Friday, October 11, 2013 2:25 PM
    Moderator
  • Thanks! That was the fix!
    Friday, October 11, 2013 2:38 PM