locked
How to handle child grid's selection changed event using MVVM RRS feed

  • Question

  • I have a grid and a child grid . i am able to raise command for selection changed event of grid .

    But when i am trying to raise it from child grid it is not working .

    Please let me know if anyone knows how to handle it.

     

     

    Tuesday, October 4, 2011 10:03 AM

Answers

  • Try this for inner grid:

    SelectedItem="{Binding Path=DataContext.OuterGridSelectedPropertyName,
                                 RelativeSource={RelativeSource Mode=FindAncestor,
                                  AncestorType={x:Type ViewLayer:ViewName}},


    Vote as Helful
    • Marked as answer by roomaL Wednesday, October 5, 2011 7:43 AM
    Tuesday, October 4, 2011 12:01 PM

All replies

  • Hi,

    Are you sure that your child grid is properly binded to the view model object. [you can verify this in visual studio out put window]

    If binding is not proper try to use Relative Binding.

    /Srinivas

    Tuesday, October 4, 2011 10:16 AM
  • Try this for inner grid:

    SelectedItem="{Binding Path=DataContext.OuterGridSelectedPropertyName,
                                 RelativeSource={RelativeSource Mode=FindAncestor,
                                  AncestorType={x:Type ViewLayer:ViewName}},


    Vote as Helful
    • Marked as answer by roomaL Wednesday, October 5, 2011 7:43 AM
    Tuesday, October 4, 2011 12:01 PM
  • hello,

    Thanks for your reply.

    @Srinivas : Yes i agree my binding is wrong.

    @DJ07 : Actually i have set data context to my view model in code behind . and my child grid's data context is set automatically to one of the properties of my datalayer.

    now in xaml I want binding to refer to datacontext set in code behind for that view.

    Can u please give me an example for that.

    Wednesday, October 5, 2011 6:55 AM