Given these classes:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
//...
}
}
public partial class LoginForm : StackPanel
{
private LoginRegistrationWindow parentWindow;
private LoginInfo loginInfo = new LoginInfo();
public LoginForm()
{
InitializeComponent();
//...
}
private void LoginOperation_Completed(LoginOperation loginOperation)
{
if (loginOperation.LoginSuccess)
{
// Here I need to access MainPages's DataContext property and set it with my ViewModel
}
}
}
I want to set MainPage's DataContext property inside LoginFrom. So I created the static instance of the MainPage class in the class itself:
public partial class MainPage : UserControl
{
public static MainPage Instance { get; private set; }
public MainPage()
{
InitializeComponent();
Instance = this;
}
}
Now I can access to the MainPage's DataContext this way:
MainPage.Instance.DataContext = new NotificationItemViewModel();
Now I'd like to hear your ideas about this kind of passing data between classes in a Silverlight application. Do you have any idea?
PS: actually I answered my original question here on Stackoverflow. But I'd like to hear your ideas in terms of code review.