c# - Bind DataGridTextColumn to method WPF -
is possible bind datagridtextcolumn method in xaml.cs?
this xaml
<my:datagrid.columns> <my:datagridtextcolumn binding="{binding iditem}" header="id item" width="150" isreadonly="true"/> <my:datagridtextcolumn binding="{binding concatenarmoneda}" header="costo" width="*"/> </my:datagrid.columns>
and want bind second column following function
private string concatenarmoneda { { return viewmodel.registro.costo.tostring() + " " + viewmodel.registro.sosmoneda.descripcion; } }
this should result in 2 properties being concatenated in same column
i have seen working textblock not working in case.
update more code requested
this whole grid
<grid grid.row="2" background="{dynamicresource grisoscuro}"> <my:datagrid enablerowvirtualization="false" x:name="datagriddatos" margin="32" horizontalalignment="stretch" verticalalignment="stretch" autogeneratecolumns="false" background="white" selectionchanged="datagriddatos_selectionchanged" selecteditem="{binding registro}" itemssource="{binding registros}" isenabled="{binding datagriddatosestado}" selectedindex="{binding indiceactual}" isreadonly="true"> <my:datagrid.columns> <my:datagridtextcolumn binding="{binding iditem}" header="id item" width="150" isreadonly="true"/> <my:datagridtextcolumn binding="{binding sosproveedor.nombre}" header="proveedor" width="150" isreadonly="true"/> <my:datagridtextcolumn binding="{binding sosservicio.descripcion}" header="servicio" width="*"/> <my:datagridtextcolumn binding="{binding sosubicacion.descripcion}" header="ubicacion" width="*"/> <my:datagridtextcolumn binding="{binding sostipopagoitem.descripcion}" header="tipo pago item" width="*"/> <my:datagridtextcolumn binding="{binding fechainiciovigencia , stringformat={}{0:dd/mm/yy}}" header="fecha inicio" width="*"/> <my:datagridtextcolumn binding="{binding estatus}" header="estatus" width="*"/> <my:datagridtextcolumn binding="{binding relativesource={relativesource findancestor, ancestortype={x:type window}}, path=concatenarmoneda,mode=oneway}" header="costo" width="*"/> </my:datagrid.columns> </my:datagrid> </grid>
that grid sorrounded parent element within xaml
on other in xaml.cs i've got concatenarmoneda function showed above
and viewmodel brings data model... using methods such this
public observablecollection<sositem> items { { if (_items == null) { _items = new observablecollection<sositem>(db.sositems.select(approw => approw)); } return _items; } set { _items = value; notifypropertychanged("items"); } }
maybe ancestor type suggest should other
ancestortype={x:type window}
?
you need use imultivalueconverter gerthermans mentioned.
<datagridtextcolumn width="70" header="costo"> <datagridtextcolumn.binding> <multibinding converter="{staticresource concatconverter}"> <binding path="costo" /> <binding path="sosmoneda.descripcion" /> </multibinding> </datagridtextcolumn.binding> </datagridtextcolumn> public class concatconverter : imultivalueconverter { public object convert(object[] values, type targettype, object parameters, cultureinfo culture) { return values[0].tostring() + " " + values[1].tostring(); } public object[] convertback(object value, type[] targettypes, object parameter, system.globalization.cultureinfo culture) { throw new notimplementedexception(); } }
Comments
Post a Comment