How to refer to the mainwindow class from another class.
Creating a WPF app. I have one main class where all the mainwindow controls are operated.
I have a different class that's called FilterManager. In this class I want to operate some data on the mainwindow as well. But I'm not sure how, what's a clean way to refer to the mainwindow from this class?
3 Replies
I tried the following, suggested by ChatGPT
But I still cannot access the listview in my WPF UI like this
You should use the MVVM pattern in which you access the
ViewModel
and set the Properties
accordingly.
The View
shouldn't initialize any API or any business logic at all.
Other than that, your ChatGPT code is fine, the reference of the MainWindow
is set through the constructor and can be accessed throughout the Class
like so this.mainWindow.weatherListView.Items.Clear();
ah yes true, that would be a lot cleaner
thanks I'll go ahead and do that