C# 如何关闭从另一个用户控件弹出的用户控件';WPF中的s按钮单击事件
我在主窗口中打开了一个用户控件child1,在该用户控件中有一些文本框和按钮C# 如何关闭从另一个用户控件弹出的用户控件';WPF中的s按钮单击事件,c#,.net,wpf,C#,.net,Wpf,我在主窗口中打开了一个用户控件child1,在该用户控件中有一些文本框和按钮 当按钮被点击时,我正在打开用户控件名child2,现在在用户控件child2上有一个关闭按钮,点击该按钮我想关闭当前用户控件 假设您正在使用弹出窗口类打开您的用户控件s 当child2关闭时,您可以关闭child1,如下所示: MainWindow.xaml.cs //Opens the child1 UserControl from MainWindow private void button_Click(obje
当按钮被点击时,我正在打开用户控件名child2,现在在用户控件child2上有一个关闭按钮,点击该按钮我想关闭当前用户控件 假设您正在使用
弹出窗口
类打开您的用户控件
s
当child2
关闭时,您可以关闭child1
,如下所示:
MainWindow.xaml.cs
//Opens the child1 UserControl from MainWindow
private void button_Click(object sender, RoutedEventArgs e)
{
UserControl1 child1 = new UserControl1();
Popup p = new Popup();
child1.ParentPopup = p;
p.Child = child1;
p.IsOpen = true;
}
UserControl1.xaml.cs
UserControl2.xaml.cs
假设您正在使用
弹出窗口
类打开用户控件
s
当child2
关闭时,您可以关闭child1
,如下所示:
MainWindow.xaml.cs
//Opens the child1 UserControl from MainWindow
private void button_Click(object sender, RoutedEventArgs e)
{
UserControl1 child1 = new UserControl1();
Popup p = new Popup();
child1.ParentPopup = p;
p.Child = child1;
p.IsOpen = true;
}
UserControl1.xaml.cs
UserControl2.xaml.cs
你想在用户控件之间切换吗?我不明白:你不能关闭用户控件。您可以关闭保存用户控件的窗口。试着用一个代码示例更好地解释你的问题。这里的人理解代码的速度比理解字母快:)不,我只想关闭用户控件而不是整个窗口。您可以将其属性可见性更改为“折叠”。它对你有用吗?你想在用户控件之间切换吗?我不明白:你不能关闭用户控件。您可以关闭保存用户控件的窗口。试着用一个代码示例更好地解释你的问题。这里的人理解代码的速度比理解字母快:)不,我只想关闭用户控件而不是整个窗口。您可以将其属性可见性更改为“折叠”。对你有用吗?
public Popup ParentPopup { get; set; }
public UserControl2()
{
InitializeComponent();
}
//Closes the child2 UserControl
private void button_Click(object sender, RoutedEventArgs e)
{
ParentPopup.IsOpen = false;
}