Vote count:
0
I have the following setup and I'm wondering if what I'm doing is the best approach:
Project1 //reusable code and controls
mainclass.cs
usercontrol1.xaml
usercontrol2.xaml
Project2 //referencing Project1
mainwindow.xaml //containing usercontrol1.xaml and usercontrol2.xaml
Project1 contains a class and user controls used in other projects, for example Project2. As the mainwindow in Project2 is initialized I create a new instance of mainclass and pass it as variable to the usercontrols, I also pass the usercontrols as variables to the mainclass.
In this way from the mainclass I can have access to all public methods and variables in the usercontrols and vice versa. Is this a good approach?
public partial class MainWindow : Window
{
public MainClass MC = new MainClass();
public MainWindow()
{
InitializeComponent();
MC.usercontrol1 = this.usercontrol1;
MC.usercontrol2 = this.usercontrol2;
usercontrol1.mainClass = MC;
usercontrol2.mainClass = MC;
}
...
I know that part of this would be more appropriate if done via Events, but the number of methods and variables I need to cross-access between the class and the usercontrols is very high, and doing this way seems to work just fine...
Thanks!
asked 4 mins ago
Aucun commentaire:
Enregistrer un commentaire