locked
How to dynamically get a list of items in vertical grid view

    Question

  • Hi,

    I have a grid view populated with my own data source. And i display it as a horizontal list of items in fullscreen view.

    In snapped views, I show it as vertical view with list of items. When i do so, my item template definition is to have only the tiltle display in the vertical list and the grid containing all details will be hidden. When, title is clicked, the border that holds the grid will be displayed.

    Question:

    Is there a way to dynamically identify the first item alone and expand it (that is, set border's visibility to true) so that the first item alone is displayed in a detailed view?

    For instance, lets say i have 5 items A,B,C,D,E

    A- ComputerA

    Adata1

    Adata2...Adatan

    B-Computer B

    Bdata1 ---- Bdatan

    Now in snap view, I'll show just A-ComputerA, B-Computer B. When user clicks on A, I'll show Adata1...Adatan

    I will now need to automatically expand and show A's content alone, can you please throw some light on how this could be done?

    Thanks!

    Monday, August 4, 2014 6:14 PM

Answers

  • If the GridViews are containing your own custom types you could implement INotifyPropertyChanged, add a new property, bind this property to the Border's visibility with a OneWay binding(as opposed to a OneTime binding), then add a handler to the vertical GridView, for example on the event Loaded or SizeChanged, then alter this property in said handler.  If you need access to the first element you can access it via
    GridView^ g1 = safe_cast<GridView^>(sender);
    YourType^ yt1 = safe_cast<YourType^>(g1->Items->GetAt(0));
    

    where sender is the first argument of your event handler
    Sunday, August 17, 2014 6:25 PM

All replies

  • Can you explain what you are doing more clearly?

    Typically the pattern I think you're following would be done by having separate GridView (for horizontal) and ListView (for vertical) each bound to the same underlying data. Each control can have its own item template showing data appropriate for the view.

    --Rob

    Tuesday, August 5, 2014 8:09 PM
    Moderator
  • I have 2 gridviews (even for a vertical view) with same data source groups as you said.

    Now let me talk about the vertical gridview

    My item template will show a header that will have just abstract information. Beneath it i will have one more border containing a grid that will hold more information. I will keep that hidden and will expand that on item click.

    Now my question is, how would i get to expand the first item(i mean the border containing grid that is present beneath the header) automatically. All i want to achieve here is to show the users that these are expandable, by expanding that one item.

    Thaks!

    Thursday, August 7, 2014 5:44 PM
  • If the GridViews are containing your own custom types you could implement INotifyPropertyChanged, add a new property, bind this property to the Border's visibility with a OneWay binding(as opposed to a OneTime binding), then add a handler to the vertical GridView, for example on the event Loaded or SizeChanged, then alter this property in said handler.  If you need access to the first element you can access it via
    GridView^ g1 = safe_cast<GridView^>(sender);
    YourType^ yt1 = safe_cast<YourType^>(g1->Items->GetAt(0));
    

    where sender is the first argument of your event handler
    Sunday, August 17, 2014 6:25 PM