Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to access a class declared in MainWindow from another window?

$
0
0

Hi all,

I'm new to wpf. I added a new class to my project to hold global data (globalData.cs) using the Solution Explorer (add class). I'm using it in my MainWindow to store some info. I added another two windows (stage_1 and Stage_2) to my project as I want to move from one to the next like a wizard (but simpler) and save data to this globalData (variable/instance?) as I progress through the program. How do I access the stageData (variable/members?) from the other windows? Thanks.

Here is the declaration of stageData in MainWindow:

public partial class MainWindow : Window { GlobalData stageData = new GlobalData { currentStage = 0 }; //init to fist stage public MainWindow() { InitializeComponent(); } private void ButtonBrowse_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); // .....etc, etc }

//etc, etc }


This is what I want to do but Stage_1 can't see stageData:

public partial class stage_1 : Window {

//Need something to access stageData.currentStage !!

public stage_1() { InitializeComponent(); } private void ButtonNext_Click(object sender, RoutedEventArgs e) { //I want to access stageData.currentStage here! } }

This only shows one variable (stageData.currentStage) but they'll be many more.Thanks


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>