c# - Difference between HierachicalDataTemplate and DataTemplate with ItemsControl -


i know real differences between hierarchicaldatatemplate , datatemplate itemcontrol within datatemplate.

here sample code:

mainwindow.xaml

<window x:class="wpfapplication2.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:test="clr-namespace:wpfapplication2"         title="mainwindow" height="350" width="525">     <window.resources>         <datatemplate datatype="{x:type test:teamviewmodel}">             <textblock text="{binding path=name}"/>         </datatemplate>          <!--<hierarchicaldatatemplate datatype="{x:type test:teammanagerviewmodel}"                                   itemssource="{binding path=teams}"/>-->          <datatemplate datatype="{x:type test:teammanagerviewmodel}">             <itemscontrol itemssource="{binding path=teams}"/>         </datatemplate>      </window.resources>     <grid>         <contentcontrol content="{binding}"/>     </grid> </window> 

viewmodel.cs

public class viewmodel : inotifypropertychanged {     #region inotifypropertychanged members      /// <summary>     /// event used binding     /// </summary>     public event propertychangedeventhandler propertychanged;      /// <summary>     /// notifies property has changed     /// </summary>     /// <param name="requestname">the property name</param>     protected virtual void onpropertychanged(string propertyname)     {         propertychangedeventhandler handler = this.propertychanged;         if (handler != null)         {             handler(this, new propertychangedeventargs(propertyname));         }     }      #endregion } 

teammanagerviewmodel.cs

public class teammanagerviewmodel : viewmodel {     private observablecollection<teamviewmodel> _teams;      public teammanagerviewmodel(observablecollection<teamviewmodel> teams)     {         _teams = teams;     }      public observablecollection<teamviewmodel> teams     {         { return _teams; }         set         {             _teams = value;             onpropertychanged("teams");         }     } } 

teamviewmodel.cs

public class teammanagerviewmodel : viewmodel {     private observablecollection<teamviewmodel> _teams;      public teammanagerviewmodel(observablecollection<teamviewmodel> teams)     {         _teams = teams;     }      public observablecollection<teamviewmodel> teams     {         { return _teams; }         set         {             _teams = value;             onpropertychanged("teams");         }     } } 

so result of list of names appearing in window. if replace datatemplate of teammanagerviewmodel commented hierarchicaldatatemplate, nothing displayed.

to me seems quite wierd itemssourceproperty of hierarchicaldatatemplate should teamviewmodel datatemplate , use it. how that?

and additional question difference between sample , msdn 1 (they seem same me, apart adding textblock in hierarchicaldatatemplate)?

https://msdn.microsoft.com/fr-fr/library/system.windows.hierarchicaldatatemplate%28v=vs.110%29.aspx

also please excuse me if wrote question badly, first time asking on so.

thanks :)

hierarchicaldatatemplates used treeviews. documentation

a treeview can populate tree binding data source , using hierarchicaldatatemplate objects.

itemscontrols don't show hierarchical data won't use template. can't off top of head name another control does... possibly menus? not sure. in treeview use of template type means you don't have add child treeview in every template doesn't represent leaf. saves time.

controls aren't designed use them won't looking them in resources.


because seem concerned it's used, opened justdecompile , did find usages on type.

the ui type references directly headereditemscontrol. types extend compatible. these include menuitem, toolbar, treeviewitem, , few wf4 designer types.

menuitems used menus, includes ribbons , context menus. toolbars that. aren't exciting. , treeviewitems used treeviews.

you can further research different types grabbing copy of justdecompile yourself, or browsing http://referencesource.microsoft.com/


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -