关闭当前的UserControl [英] Close current UserControl
本文介绍了关闭当前的UserControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Window1.xaml主窗口;并在发生一些事件之后,显示UserControl EditFile.xaml。
I have a Window1.xaml main Window; and after some event, I display a UserControl EditFile.xaml.
后面的代码是:
public static int whichSelected = -1;
private void button1_Click(object sender, RoutedEventArgs e)
{
//searchEditPanel.Children.Clear();
whichSelected = listViewFiles.SelectedIndex;
searchEditPanel.Children.Add(_EditFileControle); //this is Grid
}
现在,如何关闭打开/添加的
And now, how can I close the opened/added UserControl from its content by clicking a Cancel button or something like that?
推荐答案
您尝试过吗?
searchEditPanel.Children.Remove(_EditFileControle);
另一个建议:
也许这会有所帮助: http://sachabarber.net/?p=162
如果没有:向您的UserControl添加属性:
if it doesn't: Add a property to your UserControl:
public UserControl ParentControl {get;set;}
现在修改您的代码:
private void button1_Click(object sender, RoutedEventArgs e)
{
//searchEditPanel.Children.Clear();
whichSelected = listViewFiles.SelectedIndex;
_EditFileControle.ParentControl = this;
searchEditPanel.Children.Add(_EditFileControle); //this is Grid
}
现在您应该可以这样做:
Now you should be able to do this:
// Somewhere in your UserControl
if (this.ParentControl != null)
this.ParentControl.Children.Remove(this);
这篇关于关闭当前的UserControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文