c# - XAML:Specified element is already the logical child of another element. Disconnect it first -


i building custom modal box in wpf this modalbox example

i want users add modal children control element xaml using custom modal element. since cannot create child window inside main window. doing indirectly using xaml , c#.

here sample code implementing modal

mainwindow.xaml

<local:modalwindow>         <border background="red" width="400" height="400">             <button width="110"></button>         </border> </local:modalwindow> 

mainwindow.xaml.cs

class modalwindow : stackpanel {      public modalwindow()      {          stackpanel mygrid = this;         this.height = 400;         this.width = 400;          window mywindow = new mywindow(this);      }   class mywindow : window {      public mywindow(object x) : base()     {        this.windowstate = windowstate.maximized;         this.allowstransparency = true;         this.windowstyle = windowstyle.none;         this.opacity = 0.7;         this.background = brushes.black;         this.addchild(x);         this.showdialog();      } } 

on loading displays runtimeerror

 error: "specified element logical child of element. disconnect first" 


is there way disconnecting node mainwindow first , add exact node new window child.

please help!


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -