wpf - C# XAML - How to add a combobox to some datagrid ROWS but not others? -
i'm using key/value observable collection hold data represented in view 2 column datagrid. key values contain list of items , other key values contain single string value. using below code snippet i'm able display key values items in combobox. however, key value 'string' rows display no information , row becomes read-only. i'm trying not use code behind. doing wrong? simple solve code behind , if so, what's best approach?
<datagrid autogeneratecolumns="false" itemssource="{binding keyvaluescollection}" horizontalalignment="left" margin="10,10,10,10"> <datagrid.columns> <datagridtextcolumn header="field" binding="{binding description}" width="320"/> <datagridtemplatecolumn header="value" width="330"> <datagridtemplatecolumn.celltemplate> <datatemplate> <combobox itemssource="{binding path=valueitems}" visibility="{binding combovisible, converter={staticresource booltovis}}" displaymemberpath="valuename" selectedvaluepath="id" selectedvalue="{binding id}" /> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> </datagrid.columns> </datagrid> here structure of items:
public class keyvalue : propertychangedbase { public string description { get; set; } public list<valueitem> valueitems { get; set; } public bool combovisible = false; } valueitems list of id, string.
try using datatrigger predefined datatemplate items:
<datatemplate x:key="oneitem" datatype="{x:type valueitem}" > <textbox text="{templatebinding id}" /> </datatemplate> <datatemplate x:key="multiitems" datatype="{x:type valueitem}" > <combobox itemssource="{templatebinding valueitems}" displaymemberpath="valuename" selectedvaluepath="id" selectedvalue="{templatebinding id}" /> </datatemplate> and use content control place style accordingly. haven't tried data items have "hasmultiplevalueitems" boolean flag easy binding.
<datagridtemplatecolumn header="value" width="330"> <datagridtemplatecolumn.celltemplate> <datatemplate> <contentcontrol content="{binding}"> <contentcontrol.style> <style targettype="{x:type contentcontrol}"> <setter property="contenttemplate" value="{staticresource oneitem}" /> <style.triggers> <datatrigger binding="{binding hasmultiplevalueitems}" value="true"> <setter property="contenttemplate" value="{staticresource multiitems}" /> </datatrigger> </style.triggers> </style> </contentcontrol.style> </contentcontrol> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn>
Comments
Post a Comment