wpf - Dynamically add and remove TabItem from binded source in TabControl -


something strange happens me :-)

i've tabcontrol. itemsource binded list. here definition of tabitembase :

public class tabitembase : usercontrol {     #region properties     public virtual string tabname { get; set; }     public virtual string tabheader { get; set; }     #endregion } 

here xaml declare tabcontrol :

<tabcontrol itemssource="{binding views, mode=twoway}" itemcontainerstyle="{staticresource tabitemtemplate}"             selecteditem="{binding selectedview}" name="maintabcontrol" /> 

the style works fine because here when i'm adding view in list, works , see in tabcontrol in ui. i'm adding

view.add(new homeview()); 

then added navigationservice managing navigation name quite explicit :-). here code :

public class navigationservice {     #region ctor     public navigationservice(mainviewmodel vm)     {         viewmodel = vm;     }     #endregion      #region properties     public mainviewmodel viewmodel { get; set; }     #endregion      #region methods     public void navigateto(string viewname)     {         tabitembase view = viewmodel.views.firstordefault(v => v.tabname.equals(viewname));          if (view == null)         {             switch (viewname)             {                 case viewnames.home:                     view = new homeview();                     break;                 case viewnames.carriers:                 case viewnames.clients:                     break;                 case viewnames.commands:                     view = new commandsview();                     break;                 case viewnames.help:                 case viewnames.inputs:                 case viewnames.providers:                 case viewnames.sorts:                 case viewnames.users:                     break;                 default:                     messagebox.show(defaultmessages.navigationfailed);                     return;             }             viewmodel.views.add(view);              viewmodel.onpropertychanged("views");         }          if (viewmodel.selectedview != null && viewmodel.selectedview.datacontext != null)         {             (viewmodel.selectedview.datacontext viewmodelbase).onunloaded();         }          viewmodel.selectedview = view;         (viewmodel.selectedview.datacontext viewmodelbase).onloaded();     }     #endregion } 

i (when clicking on button):

navigationservice ns = new navigationservice(this); ns.navigateto(viewnames.commands); 

which not working. adds view in collection don't see in ui.

can me 'cause i'm begining loose hairs ?

cheers

thomas

either tabitembase must inherit tabitem instead of usercontrol or must define tabcontrol.itemtemplate.

let me know solution works you.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -