c# - User control content not rendering -


i've following code in wpf app not seeing user control contents when change value in dropdown.could advis missing please?

mainwindow.xaml:

<window         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:mainviewmodel="clr-namespace:test.viewmodel"         xmlns:viewmodel="clr-namespace:test.viewmodel.accounttypes"         xmlns:view="clr-namespace:test.view" x:class="test.mainwindow"         xmlns:views="clr-namespace:test.view.accounttypes"         xmlns:v="clr-namespace:test.view.accounttypes"         xmlns:vm="clr-namespace:test.viewmodel.accounttypes"         title="{binding displayname, mode=oneway}" resizemode="canresize" windowstartuplocation="centerscreen">     <window.datacontext>         <mainviewmodel:mainwindowviewmodel/>     </window.datacontext>      <grid>          <stackpanel grid.row="0"  horizontalalignment="left" verticalalignment="top" orientation="horizontal" height="28" width="auto" margin="5,0,0,0">             <combobox width="360" margin="1,0" itemssource="{binding accounttypes}" displaymemberpath="code" selectedvaluepath="id" selecteditem="{binding selectedaccounttype, mode=twoway}" tabindex="0" />         </stackpanel>          <contentpresenter content="{binding currentviewmodel}">         <contentpresenter.resources>                 <datatemplate datatype="{x:type viewmodel:ac1viewmodel}">                     <views:ac1view/>             </datatemplate>                 <datatemplate datatype="{x:type viewmodel:ac2viewmodel}">                     <views:ac2view/>             </datatemplate>         </contentpresenter.resources>     </contentpresenter>         </grid> 

mainwindowviewmodel.cs

  public object currentviewmodel         {             { return m_currentviewmodel; }             set             {                 m_currentviewmodel = value;                 onpropertychanged("currentviewmodel");                 }         }                 public accounttype selectedaccounttype             {                                 {                     return m_selectedsearchaccounttype;                 }                 set                 {                     m_selectedsearchaccounttype = value;                       if (selectedaccounttype.code == "ac1")                     {                         m_currentviewmodel = new ac1viewmodel();                     }                     else if (selectedaccounttype.code == "ac2")                     {                         m_currentviewmodel = new ac2viewmodel();                     }                 }             } 

thanks.

as can tell code never use currentviewmodel property, instead valorize m_currentviewmodel private member. onpropertychanged("currentviewmodel") never fired , view not getting notified currentviewmodel change.

so in selectedaccounttype property try setting currentviewmodel instead:

public accounttype selectedaccounttype {         {         return m_selectedsearchaccounttype;     }     set     {         m_selectedsearchaccounttype = value;         if (selectedaccounttype.code == "ac1")         {             currentviewmodel = new ac1viewmodel();         }         else if (selectedaccounttype.code == "ac2")         {             currentviewmodel = new ac2viewmodel();         }     } } 

Comments