c# - Binding a combobox selected item content to an element -
i working wpf using entity framework , data binding managing product , brand in database. product includes brandid property. in order display in datagrid brand name instead of id, used datagridcomboboxcolumn this:
c#
gridproducts.datacontext = this.dbcontext.products; brandcolumn.itemssource = this.dbcontext.brands;
xaml
<datagrid name="gridproducts" issynchronizedwithcurrentitem="true" roweditending="dg_roweditending" itemssource="{binding}" > <datagrid.columns> ... <datagridcomboboxcolumn header="brand" x:name="brandcolumn" displaymemberpath="brandname" selectedvaluepath="id" selectedvaluebinding="{binding path=brandid}" /> </datagrid.columns> <datagrid>
it works fine. need bind combobox selected value textbox text. tried this:
xaml
<textbox name="brand" text="{binding path=selectedvalue.content, elementname=brandcolumn}"/>
but doesn't work. idea of how can bind combobox selected value (the brandname - not brandid) in textbox?
instead of binding in xaml, create common property in entity/viewmodel , bind that.
Comments
Post a Comment