所以我有一个页面(Homepage.xaml),当我单击此页面上的一个按钮时,它会打开一个提示(Prompt.xaml)。
此提示只是我使用Homepage.cs中的window.ShowDialog();
方法创建并执行的窗口。我已经能够添加一些代码,并且当单击“否”按钮时,提示窗口已关闭,现在我发现麻烦的是“是”按钮。
我想要的是通过YES按钮将我带回到MainWindow
,到目前为止,我已经实现了这一点,但是当它打开之前的Homepage.xaml时
仍然在那里,我什至不知道如何从提示窗口关闭页面?
另一件事是,当打开MainWindow
时,它会弹出,我是否可以使其仅登陆页面而不是像新程序一样打开/弹出呢?
这是代码。
Homepage.cs
public partial class User_Homepage : Page
{
public static Page pager { get; set; }
public User_Homepage()
{
InitializeComponent();
}
public void UserLogoutBtn_Click(object sender, RoutedEventArgs e)
{
var lovmsgb = new Custom_MessageBoxes.LogoutVerification();
lovmsgb.ShowDialog();
}
}
Prompt.cs
public partial class LogoutVerification : Window
{
public LogoutVerification()
{
InitializeComponent();
}
private void YesLogoutBtn_Click(object sender, RoutedEventArgs e)
{
this.Close();
MainWindow window = new MainWindow() { WindowStartupLocation = WindowStartupLocation.CenterScreen};
window.Show();
}
private void NoLogoutBtn_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
还有 MainWindow.cs ,以防万一
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void BtnClickP1(object sender, RoutedEventArgs e)
{
mainFrame.Content = new Page1();
}
private void AdminBtn_Click(object sender, RoutedEventArgs e)
{
mainFrame.Content = new Page3();
}
}
答案 0 :(得分:0)
要检查单击了哪个按钮,应在DialogWindow中分配DialogResult
:
private void YesLogoutBtn_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
this.Close();
}
private void NoLogoutBtn_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
this.Close();
}
现在可以使用make方法在MainWindow中调用对话框并将其作为参数传递给Page1:
private void AskDialog()
{
Dialog dialog = new Dialog();
if (dialog.ShowDialog() == true)
{
mainFrame.Content = null;
}
else
{
// False action
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
frame.Content = new Page1(AskDialog);
}
在Page1中,只需在按下按钮后调用此操作:
public User_Homepage(Action askDialog)
{
InitializeComponent();
AskDialog = askDialog;
}
private readonly Action AskDialog;
private void UserLogoutBtn_Click(object sender, RoutedEventArgs e)
{
AskDialog();
}