locked
How to Access the ItemsSource in a FlipView RRS feed

  • Question

  • I have a FlipView in which I need to manually build up the flipview items to accommodate complex business rules. I have

    MyFlipView.ItemsSource = {Binding FlipViewDataSource};

    The view model populates the ItemsSource, and I need to get that data in the pages's code behind to build up the FlipView. The problem is that I don't know the event where it's possible to retrieve the data source. FlipView.Loaded doesn't help because it occurs before the ItemsSource gets popuplated. Same with Page.Loaded. How can I retrieve the data source in the page's code behind?

    Sunday, October 19, 2014 5:48 PM

All replies

  • Hi IMOsiris,

    How can I retrieve the data source in the page's code behind?

    -> MyFlipView.ItemsSource does not help?

    If you want to manually customize the FlipViewDataSource, there are two ways you could give a try:

    #1, Use a Converter class to help convert the data source to a correct one, take a look at the documentation should help you: Converter property

    #2, Instead of binding via XAML, binding via code is possible to customize everything. See Binding class for more information.

    I'm not sure if I totally understand you, if not please explain more for us, for instance in what purpose you want to access the ItemSource after the data get populated.

    However you know what is the model, you can always modify the data in Model instead of in ViewModel.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Monday, October 20, 2014 6:06 AM
    Moderator
  • I can see using a converter for when a bound value is null and I want to convert that null value to "collapsed" to hide a control. The use of the Binding class has promise, but I still don't think that that will work. Again, here's the scenario:

    1. A FlipView on my Xaml page is paired with a ViewModel using Prism.
    2. The ViewModel returns a collection of object viewmodels.
    3. My FlipView binds to that viewmodel collection through its ItemsSource.
    4. However, the presentation of that FlipView is quite complex, so I want to take that collection of ViewModels and iterate over one of its internal collections to present a very customized view.
    5. How do I get that collection of viewmodels? Not through a converter. Not through the Binding class only because I still do not know of the event that exposes the bound collection of viewmodels from my FlipView to my code behind page.

    All that I need is the collection of ViewModels that is bound to my FlipView so that I could manually spin up the underlying FlipView items. Does my request make more sense now?

    Monday, October 20, 2014 6:19 AM
  • Thanks for your explanation, let's say customize means 1, customize the data, 2, customize the layout:

    #1 Data: To customize the data, use Converter or Binding could be a good idea.

    #2 Layout: To customize the layout of FlipView, modify your FlipView ItemTemplate.

    As I understand from your scenario, you probably need customize the layout to fit your own requirement, MyFlipView.ItemsSource can help you get the data but cannot help you get the layout, I think that's why you do not want to use this.

    See this for more information: FlipViewItem styles and templates

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, October 20, 2014 7:25 AM
    Moderator
  • Clearly, I've been writing about #2. The FlipView Item Template still does not offer enough control. I need to know--assuming that it's possible--how to retrieve the data context, namely the collection of object view models, from my FlipView so that I can work up the FlipView items from code behind. Remember that the FlipView gets bound from the Xaml page's Prism-based view model.
    Monday, October 20, 2014 8:13 AM