<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.silverlight.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Dynamically creating and destroying containers</title><link>http://blogs.silverlight.net/blogs/jesseliberty/archive/2008/05/07/dynamically-creating-and-destroying-containers.aspx</link><description>Ben H. asked a question within a comment to a previous blog post. Suppose, there is a button on the main form and when the user clicks on the button, a new container gets instantiated and the new container appears on the top of the main form. However</description><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>Dew Drop - May 8, 2008 | Alvin Ashcraft's Morning Dew</title><link>http://blogs.silverlight.net/blogs/jesseliberty/archive/2008/05/07/dynamically-creating-and-destroying-containers.aspx#51973</link><pubDate>Thu, 08 May 2008 13:18:53 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:51973</guid><dc:creator>Dew Drop - May 8, 2008 | Alvin Ashcraft's Morning Dew</dc:creator><description>&lt;p&gt;Pingback from &amp;nbsp;Dew Drop - May 8, 2008 | Alvin Ashcraft's Morning Dew&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=51973" width="1" height="1"&gt;</description></item><item><title>re: Dynamically creating and destroying containers</title><link>http://blogs.silverlight.net/blogs/jesseliberty/archive/2008/05/07/dynamically-creating-and-destroying-containers.aspx#51854</link><pubDate>Wed, 07 May 2008 23:54:55 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:51854</guid><dc:creator>BenHayat</dc:creator><description>&lt;p&gt;Nick, sending you an email with my question&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;
&lt;p&gt;..Ben&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=51854" width="1" height="1"&gt;</description></item><item><title>re: Dynamically creating and destroying containers</title><link>http://blogs.silverlight.net/blogs/jesseliberty/archive/2008/05/07/dynamically-creating-and-destroying-containers.aspx#51850</link><pubDate>Wed, 07 May 2008 23:29:06 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:51850</guid><dc:creator>Radiox</dc:creator><description>&lt;p&gt;hi Ben,Jesse, &lt;/p&gt;
&lt;p&gt;If I understand right, this is what you need:&lt;/p&gt;
&lt;p&gt;instantiate a control from a separate xaml and show it from Page.xaml.cs, click on Close button and then, Page.xaml.cs will know about the click and act by hiding the control then removing it.&lt;/p&gt;
&lt;p&gt;When you click close on the instantiated control, you call a method that activates an event:&lt;/p&gt;
&lt;p&gt;public delegate void this_IsClosing();&lt;/p&gt;
&lt;p&gt;public event this_Close isClosing;&lt;/p&gt;
&lt;p&gt;private void ButtonClose_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;isClosing();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//you can hide it here if you wish&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;then, in Page.xaml.cs&lt;/p&gt;
&lt;p&gt;//this instantiates your control&lt;/p&gt;
&lt;p&gt;//make sure is known in the class&lt;/p&gt;
&lt;p&gt;//so that you can remove it later&lt;/p&gt;
&lt;p&gt;MyControl c= new MyControl();&lt;/p&gt;
&lt;p&gt;c.isClosing+=new MyControl.this_Close(doTheTrickHere);&lt;/p&gt;
&lt;p&gt;void doTheTrickHere()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;//remove the control here&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;c.Visibility = Visibility.Collapsed;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;LayoutRoot.Remove(c);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;I have this implemented in my own application. If my explanation is not good, please let me know. nick At fastcom.ie&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=51850" width="1" height="1"&gt;</description></item><item><title>re: Dynamically creating and destroying containers</title><link>http://blogs.silverlight.net/blogs/jesseliberty/archive/2008/05/07/dynamically-creating-and-destroying-containers.aspx#51828</link><pubDate>Wed, 07 May 2008 21:03:14 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:51828</guid><dc:creator>BenHayat</dc:creator><description>&lt;p&gt;&amp;gt;&amp;gt;Entirely my fault, I didn't take the time to fully understand the problem&amp;lt;&amp;lt;&lt;/p&gt;
&lt;p&gt;This is what I like about you, your honesty and being humble!!!&lt;/p&gt;
&lt;p&gt;Not a problem... Trust me, this was posted on the forum a while back and the Only response I got, was to raise an event when the User Control's Close button was pressed. &lt;/p&gt;
&lt;p&gt;Then in the main page, I have to have an event handler (who has subscribed to the raised event) to remove it from the Grid's children and set the form to null.&lt;/p&gt;
&lt;p&gt;I'm getting closer to what I want to do, and that's why I thought I get a lift or hand holding on this last part.&lt;/p&gt;
&lt;p&gt;I appreciate your effort and if you do get a chance, I'll still welcome your input!&lt;/p&gt;
&lt;p&gt;..Ben&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=51828" width="1" height="1"&gt;</description></item><item><title>re: Dynamically creating and destroying containers</title><link>http://blogs.silverlight.net/blogs/jesseliberty/archive/2008/05/07/dynamically-creating-and-destroying-containers.aspx#51817</link><pubDate>Wed, 07 May 2008 19:32:27 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:51817</guid><dc:creator>jesseliberty</dc:creator><description>&lt;p&gt;Entirely my fault, I didn't take the time to fully understand the problem (though I did enjoy working through the problem I did understand!).&lt;/p&gt;
&lt;p&gt;Okay, what you want is a bit harder (only in that I haven't thought through how to do it). &amp;nbsp;I have two suggestions: (1) definately post it to the forums so that you are not waiting for me and (2) I'll try to work on that as well.&lt;/p&gt;
&lt;p&gt;Thanks and sorry for missing the boat.&lt;/p&gt;
&lt;p&gt;-j&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=51817" width="1" height="1"&gt;</description></item><item><title>re: Dynamically creating and destroying containers</title><link>http://blogs.silverlight.net/blogs/jesseliberty/archive/2008/05/07/dynamically-creating-and-destroying-containers.aspx#51794</link><pubDate>Wed, 07 May 2008 18:10:42 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:51794</guid><dc:creator>BenHayat</dc:creator><description>&lt;p&gt;Hi Jesse;&lt;/p&gt;
&lt;p&gt;First thank you for your help. You asked me a series of questions and I answered them all to clarify an important point that you had missed in my first question and also sent you an email with screen shots that further described what I was looking for.&lt;/p&gt;
&lt;p&gt;The solution you gave wasn't what I was asking. I was mainly asking about &amp;quot;Dynamically creating USER CONTROLS&amp;quot; from the main page and destroying them from main page. You created the stackpanel with two buttons on the same page. That's easy to close or destroy.&lt;/p&gt;
&lt;p&gt;What I'm asking is, your create button should Instantiate a User Control that is in a separate Xaml file and separate class. Inside this User Control, there is a button that says &amp;quot;Close&amp;quot;. When the user Clicks on this &amp;quot;Close&amp;quot; Button inside of the User Control, I want this close button to raise an event that the &amp;quot;MainPage&amp;quot; will respond to the event and then destroy the User Control.&lt;/p&gt;
&lt;p&gt;If you go back to my last answers, I think I tried to clarify that the close button is in a different class and file than the one who created it.&lt;/p&gt;
&lt;p&gt;That's where I got the challenge!&lt;/p&gt;
&lt;p&gt;Hope thic clarifies it now!&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=51794" width="1" height="1"&gt;</description></item></channel></rss>