c# - ContentPresenter in ItemControl.ItemTemplate to show displaymemberpath of itemscontrol -


i want know there anyway put contentpresenter in itemtemplate of itemscontrol display data. don't want hard code binding text="{binding username}" cause building custom control, think contentpresenter want. after tried using contentpresenter, give me stackoverflowexception.

    <itemscontrol itemssource="{binding selecteditems, elementname=listbox}" displaymemberpath={binding displaymemberpath}">         <itemscontrol.itempanel>             <itemspaneltemplate>                 <stackpanel orientation="horizontal" isitemshost="true"/>             </itemspaneltemplate>         </itemscontrol.itempanel>         <itemscontrol.itemtemplate>             <datatemplate>                 <stackpanel orientation="horizontal">                     <textblock x:name="separator" text=", "/>                     <contentpresenter/>                     <!--<textblock text="{binding username}"/>-->                 </stackpanel>             </datatemplate>         </itemscontrol.itemtemplate>     </itemscontrol> 

that's code. if without seperator , itemtemplate, able display data using displaymemberpath, stack name together. still finding solution solve it. hope can provide ideas this.

the answer no, can't. contentpresenter supposed used in controltemplate, not datatemplate, not right control use. linked page on msdn:

you typically use contentpresenter in controltemplate of contentcontrol specify content added.

what can alternatively, declare number of datatemplates in resources section (complete binding paths) different types of data , omit x:key directives, eg. not name them. also, not specify 1 itemscontrol.itemtemplate.

when doing this, wpf implicitly select correct datatemplate relevant data type , can have different outputs different data types. see the datatype property section of data templating overview page on msdn further explanation of technique.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -