vb.net - Creating a WPF control that uses datatemplates -
i'm trying build control display items in sort of scheduling grid, placed horizontally depending on category in, , vertically depending on time scheduled , how time item take complete. inheriting system.windows.controls.control , default style , template shown below:
<style targettype="khs:timegrid"> <setter property="template"> <setter.value> <controltemplate targettype="khs:timegrid"> <border background="{templatebinding background}" borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}"> <scrollviewer horizontalscrollbarvisibility="auto" verticalscrollbarvisibility="disabled"> <dockpanel> <grid name="part_headergrid" dockpanel.dock="top"> <grid.columndefinitions> <columndefinition width="{binding actualwidth, elementname=timecolumn}"/> </grid.columndefinitions> </grid> <scrollviewer verticalscrollbarvisibility="auto" horizontalscrollbarvisibility="disabled"> <grid name="part_bodygrid"> <grid.columndefinitions> <columndefinition name="timecolumn" width="auto"/> </grid.columndefinitions> </grid> </scrollviewer> </dockpanel> </scrollviewer> </border> </controltemplate> </setter.value> </setter> </style>
for items, use interface:
public interface itimegriditem property starttime date property duration timespan end interface
rows added "bodygrid" each increment of time (representing 15 minutes default) , items given grid.row , grid.rowspan values based on start times , durations.
my problem comes in when try implement datatemplates items. i'm trying use contentpresenters display items. easy create itemtemplate property timegrid , use items, if need template items of different types unique templates?
that got me thinking how other controls can have datatemplates added resources collection different datatypes, , control knows search resources , pick right template. unfortunately haven't been able figure out how implement that. know how can accomplish this? must possible since microsoft in controls.
i don't know enough specific implementation give exact answer i'd using wrapper control apply custom template , place contentcontrol within renders child view whatever they've been templated themselves.
to honest though wouldn't use grid this, way i've done in past data binding. create view model items want display , give x , y properties. in xaml draw them single itemscontrol has canvas background , binds item's canvas.top , canvas.left dp's x , y's. way view model code has complete freedom position children want them , can unit-test without having invoke view classes themselves. once stopped trying overly-clever xaml, , stuck using loosely coupled data-binding, complex gui designs became easy implement.
Comments
Post a Comment