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

  • Home
  • SEARCH
  • 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 8510527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:43:49+00:00 2026-06-11T03:43:49+00:00

i have in the main window variable example: public partial class MainWindow : Window

  • 0

i have in the main window variable

example:

public partial class MainWindow : Window
{
   internal int i;
    public MainWindow()
    {
        InitializeComponent();
    }
}

and i want to use him in child window and for that i do him internal (the two window in the same namespace) and the child window still doesn’t recognize the variable

what i’m suppose to do?

  • 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-11T03:43:50+00:00Added an answer on June 11, 2026 at 3:43 am

    You should create a public property on the child window of type int. When you create the child window then set that property based on the value of the field in the parent window.

    It appears that you want to be able to not just read the variable in the child class, but also modify it and have that change reflected in the parent form, so that will complicate the answer.

    We’ll need to start off with a helper class. Because the data we’re interested in is an int (which is a value type) we’ll need something that is a reference type (i.e. a class).

    public class Wrapper<T>
    {
        public T Value { get; set; }
    }
    

    So we’ll start by not having an integer in the parent form, but instead an instance of this class:

    public class Form1
    {
        private Wrapper<int> data = new Wrapper<int>(); //TODO give better name
        //...
    }
    

    Next we’ll need a public property on the child form; rather than an int we’ll use this new class:

    public class Form2
    {
        public Wrapper<int> Data { get; set; }
        //...
    }
    

    Now when we create the child class we’ll set the property based on the value in the parent class:

    public void someMethod()
    {
        Form2 childForm = new Form2();
        childForm.Data = data;
        childForm.Show();
    }
    

    Now that we’ve done all this we’ve ensure that both the parent and child class have a reference to the same instance of Wrapper, so any changes to the Value property of the Wrapper instance (from either class) will be “seen” by either reference.

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

Sidebar

Related Questions

I have a main window, that opens another window. I want to close this
I have a quesion about how to access main window's variable from popup window.
I have main window which has inner grid components. When I press a button
I have a main window with a Gtk Button named openDialog. If I click
I have a main window where all the work is done. When i open
I have a main menu window. On clicking any menu item it opens a
I have a window(say main window) with a frame which has a page in
I have a page viewer as main window showing an external page as we
i have a mvvm app that the main window is a tab control. i
I have an application with a main window that loads in text file(s) and

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.