wpf - tab control data template -
i want tabcontrol each tab item represents (employee)viewmodel; header should displayname property of view model, , content should user control (employeedetailsview) has data context of view model.
so pidgeon xaml (is there such thing??):
<tabcontrol x:name="items"> <tabitem header="displayname" content=local:employeedetailsview /> <tabcontrol>
what should real xaml like?
cheers,
berryl
edit vortex
<tabcontrol x:name="items" > <tabcontrol.itemtemplate> <datatemplate> <textblock text="{binding displayname}" /> </datatemplate> </tabcontrol.itemtemplate> <tabcontrol.contenttemplate> <datatemplate> <contentcontrol> <local:employeedetailview/> </contentcontrol> </datatemplate> </tabcontrol.contenttemplate> </tabcontrol>
in wpf quite simple. in silverlight used custom tabcontrol.
silverlight
you can find source , example here (mytabcontrol.cs), i've answered similar question.
and code must like:
<my:mytabcontrol x:name="mytabs" myitemssource="{binding items}" myselecteditem="{binding selecteditem}" > <my:mytabcontrol.tabheaderitemtemplate> <datatemplate> <textblock text="{binding displayname}" /> </datatemplate> </my:mytabcontrol.tabheaderitemtemplate> <my:mytabcontrol.tabitemtemplate> <datatemplate> <local:employeedetailsview /> </datatemplate> </my:mytabcontrol.tabitemtemplate> </my:mytabcontrol>
in code-behind or somewhere:
var items = new list<employee>(){ new employee{displayname = "employee 1"}, new employee{displayname = "employee 2"}}; mytabs.datacontext = new somecollectionmodel { items = items, selecteditem = items[0] };
wpf
wpf has built-in support of datatemplates in tabcontrol, have few minor changes in xaml:
<tabcontrol x:name="mytabs" itemssource="{binding items}" selecteditem="{binding selecteditem}"> <tabcontrol.itemtemplate> <datatemplate> <textblock text="{binding displayname}" /> </datatemplate> </tabcontrol.itemtemplate> <tabcontrol.contenttemplate> <datatemplate> <local:employeedetailsview /> </datatemplate> </tabcontrol.contenttemplate> </tabcontrol>
Comments
Post a Comment