문제

How can I access a variable in MainWindow.xaml.cs that is defined as public from Window1.xaml.cs?

I thought that if a variable is defined that way I will be able to access it from anywhere. What am I missing here?

도움이 되었습니까?

해결책

I thought that if a variable is defined that way I will be able to access it from anywhere

Unless the variable is both public and static, you can't access it from almost anywhere coz that should be accessed based on a certain instance of an object.

If you wanna access a variable from any window, either make it static or call it based on an instance of that window like

Window1 win = new Window1();
win.Variablex = 1;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top