c# - Change column style depending of source -
i trying populate datagrid 1 column combobox need when collection binded combobox empty column becomes textbox column. have defined columns below:
binding binding = new binding("datacontext.prices"); binding.relativesource = new relativesource(relativesurcemode.findancestor, typeof(usercontrol),1);
datagridcomboboxcolumn productprices = new datagridcomboboxcolumn() { elementsyle = new style { targettype = typeof(combobox), setters = { new setter { property=combobox.itemssourceproperty, value= binding } } }, editingelementsyle = new style { targettype = typeof(combobox), setters = { new setter { property=combobox.itemssourceproperty, value= binding } } }, displaymemberpath = new binding("price"); selectedvaluepath = new bindnt("price"); }; mydatagrid.columns.add(productprices); mydatagrid.columns.add(new datagridtextcolumn(){ header="name", binding=new binding("name")}); and defined mydatagrid:
<datagrid name="mydatagrid" itemssource="{binding products}" /> in viewmodel create
var products = new list<product> { new product { name="prod 1", price="12.5" } } var prices = new list<pricel> { new pricel { price="12.5" }, new pricel { price="10" } } icollectionview products = collectionviewsource.getdefaultview(products); icollectionview prices = collectionviewsource.getdefaultview(prices); i need when "prices" empty column become in textbox working mvvm , tried elementstyle cannot see event in combobox let me verify it's data source. body me ??
i found 1 way
<usercontrol.resources> <datagrid itemssource={binding} x:key="datagrid1"> <datagrid.columns> <datagridtextcolumn binding="{id}"/> <datagridtextcolumn binding="{name}"/> </datagrid.columns> </datagrid> <datagrid itemssource={binding} x:key="datagrid2"> <datagrid.columns> <datagridtextcolumn binding="{id}"/> <datagridcheckboxcolumn binding="{accepted}"/> </datagrid.columns> </datagrid> </usercontrol.resources> <grid> <contentcontrol content="{staticresource datagrid1}" datacontext="{binding mytable}" name="mycontent"/} </grid> y por codigo puede cambiarse el content
mycontent.content = this.findresource("datagrid2");
Comments
Post a Comment