0

I was solving Windows Phone 8.1 ListView wobbling problem and had code like below, however, once I add the ItemTemplate, the contents of the List cannot be seen, I'm wondering why and how to fix the problem.

 <ListView
            Grid.Row="1"
            x:Name="ListViewEvents"
            Loaded="OnListViewEventsLoaded"
            ItemsSource="{Binding xx}"
            ItemTemplateSelector="{StaticResource xx}"
            ItemContainerStyle="{StaticResource xx}"
            IsItemClickEnabled="True">

            <ListView.ItemTemplate >
                <DataTemplate >
                    <Grid Width="{Binding ActualWidth, ElementName=EventsListGrid}" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
litaoshen
  • 1,762
  • 1
  • 20
  • 36
  • the `Grid` does not have any content inside, of course it looks invisible. If you want to see something, try adding some `Background` for the Grid. That's just for testing. You need some other content control inside to show the value from each item. – King King Oct 21 '15 at 00:24
  • @KingKing I thought that it was supposed to show the Items from ItemsSource, the original code without the ItemTemplate don't have the background either, but the items can be shown – litaoshen Oct 21 '15 at 12:52
  • so do you see the shown items? `ListViewItem` is a `ContentControl`, you change the item template without hooking any `Content` with the inner Controls, how could it be shown? BTW, in the default template, it has a `ContentPresenter` - which is what helps showing the Content for you to see. – King King Oct 21 '15 at 12:53
  • @KingKing No, you can't see item from itemsource. I tried to put ItemSource inside the ItemTemplate, but it doesn't work, seems I cannot put it inside the ItemTemplate, do you know the way to modify the code so that I can show the items from the itemsource? Thank you! – litaoshen Oct 21 '15 at 13:02
  • `ItemTemplate` is just for 1 item. I don't understand what you want. The problem here is there is not any item shown. Try searching around on how they create `ItemTemplate` for a `ListView`, you'll get the answer. It's just simple, such as you can add a `` inside the `Grid` to see it works. – King King Oct 21 '15 at 13:06
  • @KingKing What I want is to get items shown in the ListView while at the same time use the ItemTemplate to solve the scroll wobbling effect this is a reference http://stackoverflow.com/questions/24361850/listview-in-windows-phone-8-1-wobbles-while-scrolling-though-long-list-xaml – litaoshen Oct 21 '15 at 15:01

1 Answers1

0

Your Width binding is trying to read the ActualWidth property of an element in your XAML named EventsListGrid, but there's no such element in the sample code you've provided. As such, the binding engine is unable to set the Width property on your grid, most likely setting it to some unset/NaN value. At least I can confirm this when setting up a similar case as the one you provided and inspecting in Snoop the ListViewItem containers generated for each item in the test collection bound to the ListView. Perhaps you want to set the element name to ListViewEvents in this case or some other parent element not shown in the example?

mvromer
  • 144
  • 4
  • Thank you for your time. I didn't paste all the code, my bad. EventsListGrid is the name of the grid where this ListView is contained. So do you have any advice? – litaoshen Oct 21 '15 at 12:49