Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:35:13+00:00 2026-06-15T19:35:13+00:00

I am trying to learn how to call methods throughout a Wpf application. In

  • 0

I am trying to learn how to call methods throughout a Wpf application.

In a basic experiment, I have two pages, PageData and MainPage.

PageData code:

namespace AppName
{
    public sealed partial class PageData 
    {
        public PageData()
        {
            this.InitializeComponent();
        }

        // works
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            mTest();
        }

        public bool mTest()
        {
            var newTbx = new TextBox{
                Text = "Hello",
                FontSize = 50
                };

            Grid.SetRow(newTbx, 3);
            Grid.SetColumn(newTbx, 3);
            gridMainPageData.Children.Add(newTbx);

            return true;
        }
    }
}

MainPage code:

namespace AppName
{
    public sealed class MainPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void pageRoot_Loaded(object sender, RoutedEventArgs e)
        {
             PageData passCall = new PageData();

             mDisplayAlert(passCall.mTest().ToString());
        }
    }
}

It seems that the method mTest() completes because I get the “true” response when MainPage loads (I have a method mDisplayAlert that I use for showing messages on the MainPage UI), but the UI on PageData does not change. I know that mTest() works because the button click event on PageData does work.

Why does the UI not update when called from MainPage?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:35:15+00:00Added an answer on June 15, 2026 at 7:35 pm

    Because you create a new instance of PageData inside MainPage when what you really want to do is use the same instance to access the exact same controls. When you call the .test() method you create a totally new TextBox and assign data to a totally new Grid when you think you are writing on you first PageData instance.

    You have many options from there. You can :

    • Pass a reference of the PageData instance to you other form when you create it.
    • Create an event between the two classes with a reference to the PageData instance.
    • Make your method and controls Static in PageData to make sure the whole program share the same instance. (Not recommanded at all)
    • If you want a little work around, you can always set you method to Static and create a Static copy of the control’s instance. Then the compiler will ask for a reference of a Static control and you can assign the instance copy using Controls.Find(yourControl).(Not a good practice either).

    Personally i’d use option number 1 but now you know you have the choice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to learn about php's arrays today. I have a set of arrays like
Im trying to learn a bit about c++ and have run in to some
I'm trying to learn how to add new methods in the String.prototype in JavaScript.
Novice programmer here. trying to learn static methods and recursion. No idea why I
I am trying to learn Guice and I have a question on how to
I'm trying to learn more about the .egg concept and overriding methods in Python.
I am trying to learn object oriented javascript. Why is this call to an
I'm trying to learn dependency injection and have come across a problem, when unit
i am trying to learn abit about recursive methods and is writing a method
I am trying to learn a few different methods of calling functions by address.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.