【发布时间】:2016-02-23 11:09:45
【问题描述】:
我有一个Page,它加载在Window 中。当用户登录时,我想在Window 中显示Image,但是登录方法在Page 中。我试图在Window 中调用一个方法,该方法用于显示MessageBox 但不显示Image。这是一些代码;
主窗口
public void initUI()
{
navigationFrame.Navigate(new Uri("View/MainPages/LoginPage.xaml", UriKind.Relative));
}
public void ShowSDCImage()
{
sdcLogo.Visibility = Visibility.Visible;
MessageBox.Show("Test"); // This is displayed
}
子页面
private void EnterPressed(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
if (UserAuthenticationService.AuthenticateUser(passwordBox.Password))
{
var lGs = new LoginService();
var sqlServerCheck = new MySQLServerCheck();
if (sqlServerCheck.ServerIsOnline())
{
MainWindow mw = new MainWindow();
mw.ShowSDCImage();
NavigationService.Navigate(new Uri("View/MainPages/DashboardPage.xaml", UriKind.Relative));
}
else
{
MessageBox.Show("Sorry, the server is offline. Please notify IT.");
}
}
else
{
MessageBox.Show("Incorrect Password");
}
e.Handled = true;
}
if (e.Key == Key.Escape)
{
Application.Current.Shutdown();
}
}
正如您在 MainWindow 中看到的,我正在尝试使用
MainWindow mw = new MainWindow();
mw.ShowSDCImage();
虽然这会显示MessageBox,但它不会显示Image。我做错了什么,如何成功访问 MainWindow 的Image?
【问题讨论】: