c# - WPF How to Bind an Image to a DataGrid column as a property of the ItemsSource? -
i'm creating wpf app using mvvm design pattern.
i have datagrid 4 columns , want last column column of images. other 3 text columns bound properties of attributenode
contained in list attributes
, used itemssource
.
xaml
<usercontrol.datacontext> <viewmodel:attributegridviewmodel /> </usercontrol.datacontext> ... <datagrid name="attributegrid" horizontalalignment="stretch" verticalalignment="stretch" itemssource="{binding attributes}" autogeneratecolumns="false"> <datagrid.columns> <datagridtextcolumn header="parameter" binding="{binding parameter}" minwidth="30" width="225" fontsize="15"/> <datagridtextcolumn header="value" binding="{binding value}" minwidth="30" width="*" fontsize="15"/> <datagridtextcolumn header="ip address" binding="{binding ipaddress}" minwidth="10" width="120" fontsize="15"/> <datagridtemplatecolumn header="conflict" width="50"> <datagridtemplatecolumn.celltemplate> <datatemplate> <!-- area of confusion --> <image source="{binding ???}" /> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> </datagrid.columns> </datagrid>
attributegridviewmodel & attributenode
in attributegridviewmodel
set attributes using line this:
attributes = configutility.getattributenodes(value);
below part of attributenode
class :
public class attributenode { public string parameter { get; set; } public string value { get; set; } public string ipaddress { get; set; } public string imagesource {get; set; } public char type { get; set; } ... }
you can see properties here , how attach parameter, value, , ipaddress properties own columns.
but if try image source binding error :
question
i'm not sure yet if can bind string represents image path guess more importantly how can access , data bind property imagesource
item of type attributenode
in the itemssource attributes
(a list of attributes
)for datagrid? implementation works other 3 columns , updates correctly based on changes in viewmodel. how access property did previously?
for wondering how resolved issue...
it appears resharper issue , creating new attribute
this
new attribute("","","","../icons/checkmark.png")
works though resharper claims can't find imagesource
property. datacontext set correctly during run time. images show in column now.
Comments
Post a Comment