binding - WPF pass DataGrid selected row as command parameter -
- mainwindowviewmodel has viewcustomercommand(string id) command shows customer id
- mainwindow.xaml containing tabcontrol
- tabcontrol has usercontrol contains datagrid bind customers collection
| id | customer |
how pass "id" column in datagrid selected row command parameter in mainwindow.xaml
mainwindow.xaml <button command="{binding viewcustomercommand}" commandparameter="??? how pass id of selected customer ???" />
well if need expose selecteditem within usercontrol why don't extend such property?
e.g.
public class myusercontrol : usercontrol { private static readonly sometype selecteditemproperty = dependencyproperty.register("selecteditem", typeof(sometype), typeof(myusercontrol)); public sometype selecteditem { { return (sometype)getvalue(selecteditemproperty); } set { setvalue(selecteditemproperty, value); } } } so can bind selecteditem of datagrid in usercontrol selecteditem property.
<myusercontrol> <datagrid selecteditem="{binding selecteditem, relativesource={relativesource findancestor, ancestortype={x:type myusercontrol}}" /> </myusercontrol> now have find way access selecteditem property in tabitem. i'm leaving part you.
please note, illustration of idea , may contain small errors.
Comments
Post a Comment