binding - WPF pass DataGrid selected row as command parameter -


  1. mainwindowviewmodel has viewcustomercommand(string id) command shows customer id
  2. mainwindow.xaml containing tabcontrol
  3. 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

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -