我对WPF不熟悉,正在尝试构建我的第一个应用程序,它是多流的多视图器,用于学习。
我在主窗口上有24个多媒体元素,我想全屏选择多媒体元素时,再点击一次,以最小化这个全屏媒体。
代码是这样的
foreach (var item in MediaElements)
{
item.LoadedBehavior = MediaState.Manual;
item.MouseEnter += mediaElement1_MouseEnter;
item.MouseLeave += mediaElement1_MouseLeave;
item.Loaded += mediaElement1_Loaded;
item.MouseLeftButtonUp += (o, args) =>
{
if(!fullscreen)
{
ListOfMedia.Children.Remove(item);
this.Content = item;
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
}
else
{
this.Content = ListOfMedia;
ListOfMedia.Children.Add(item);
this.WindowStyle = WindowStyle.SingleBorderWindow;
this.WindowState = WindowState.Normal;
}
fullscreen = !fullscreen;
};
当我第一次单击它时,它工作得很好,窗口的屏幕大小正在变大,但是当我下次单击它以最小化它时,有一个异常对我说
System.ArgumentException: 'Must disconnect specified child from current parent Visual before attaching to new parent Visual.'
我检查了一些stackoverflow问题,但找不到正确的解决方案,有人在谈论从父目录树中删除子目录的扩展方法,我写了这个扩展方法,但我不知道问题是什么,这个问题背后有什么想法?我必须删除的内容以及正在发生的事情。
请告诉我这里发生了什么。