Need Help with Composite UI Architecture Block (CAB) - SmartParts not Disposing RRS feed

  • Question

  • Hi,

    I'm trying to make some simple modifications to an application built using CAB (Composite UI Architecture Block). I have a very high level understanding of this architecture from digging into it a little bit months ago when I was first introduced to this project.


    One screen of the application has a TabControl which is part of a parent SmartPart UserControl and already has several TabPages. Each of these TabPages has its own SmartPart part UserControl. This is all laid out at design time. What I'm trying to do is add a new TabPage containing a SmartPart UserControl only if a certain criteria is met.


    My first attempt took this exact approach, to check if my criteria is met, and if it is, create the tab page and my UserControl (let's call the class UserControl1) in the load event of the parent SmartPart, and add it to the TabControl. Well through trial and error I discovered that the dependency injection (my UserControl's presenter; using MVP) was never created doing it this way.


    My next attempt was to move that code from the Load Event into the constructor of the parent smart part. This seemed to work correctly. So I guess that CAB some how iterates through the child controls of a SmartPart searching for other SmartParts to setup. The problem is if I remove this tab page, and then try to add it again, I get an error saying that my instance of UserControl1 already exists. When I look in the WorkItem.Items collection, I can see that that object is in fact there.


    So what I don't understand is, why are all of the other tab pages and smart parts removed and able to be added again, but not mine when I manually remove and call dispose on UserControl1? How do I get rid of that tab page if my criteria is no longer met? I know this is probably not enough information to fully come up with an answer but I'm not sure what else is relevant. Thanks!

    Monday, November 17, 2008 9:13 PM