none
Listview first item not shown RRS feed

  • Question

  • Today I encounter a strange problem when I development in Windows 8.1 RT

    First item in ListView not shown.

    but It still can be click, and layout still reserve that item space like picture below.

    My XAML

      <Grid>
                            <ListView x:Name="lv_Content" FlyoutBase.AttachedFlyout="{StaticResource flyout_Resoultion}"  IsItemClickEnabled="True" SelectionMode="Single" ItemClick="lv_Content_ItemClick">
    
                                <ListView.ItemTemplate>
    
                                    <DataTemplate>
                                        <Grid Width="{Binding ActualWidth , ElementName=lv_Content}" Height="60" Margin="0,0,0,20" >
                                            <Border BorderBrush="#FFB3BBB6" BorderThickness="10,0,0,0" >
                                                <Grid>
    
                                                    <TextBlock Grid.Row="1" TextWrapping="Wrap"  Text="{Binding part}" FontSize="24" Margin="10,0,0,0" FontFamily="Global User Interface" VerticalAlignment="Center"  />
    
                                                </Grid>
    
                                            </Border>
                                        </Grid>
                                    </DataTemplate>
    
                                </ListView.ItemTemplate>
                                  
                            </ListView>
                        </Grid>

    BEHIND CODE

         private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
            {
                sdj_temp = e.NavigationParameter as shows_detail_json;
    
                List<YoutubeVideoId> l_yvd = new List<YoutubeVideoId>() { new YoutubeVideoId() { part = "Part: 1", Id = "1ass" }, new YoutubeVideoId() { part = "Part: 2", Id = "2ass" }, new YoutubeVideoId() { part = "Part: 3", Id = "3ass" } };
                YoutubeVideoId yvd;
                int i = 1; 
    
                lv_Content.ItemsSource = l_yvd;
            }
    
            class YoutubeVideoId
            {
                public string part { get; set; }
                public string Id { get; set; }
            }

    Is anyone happen before?...

    I used ListView many time, but this time I encounter this really strange problem.


    thanks!

     

    • Edited by THKAW Tuesday, November 18, 2014 8:51 AM
    Tuesday, November 18, 2014 8:44 AM

Answers

  • I think I found the answer.

    When I set lv_Content.ItemsSource in NavigationHelper_LoadState()

    The lv_Content.ActualWidth and ActualHeight both are "0.0"

    which mean lv_Content's Itemtemplate width is binding to 0.0

    <Grid Width="{Binding ActualWidth , ElementName=lv_Content}" Height="60" Margin="0,0,0,20" >

    No matter what I binding Grid Width to RootGrid or HorizontalAlignment="Stretch" VerticalAlignment="Stretch" in ListView are useless.

    But that is really strange because Second item and after all item still get valid ActualWidth and Height...

    So I move lv_Content.ItemsSource to Loaded() Event, then that will fix this problem.

    • Marked as answer by THKAW Wednesday, November 19, 2014 3:42 AM
    Wednesday, November 19, 2014 3:42 AM

All replies

  • I think I found the answer.

    When I set lv_Content.ItemsSource in NavigationHelper_LoadState()

    The lv_Content.ActualWidth and ActualHeight both are "0.0"

    which mean lv_Content's Itemtemplate width is binding to 0.0

    <Grid Width="{Binding ActualWidth , ElementName=lv_Content}" Height="60" Margin="0,0,0,20" >

    No matter what I binding Grid Width to RootGrid or HorizontalAlignment="Stretch" VerticalAlignment="Stretch" in ListView are useless.

    But that is really strange because Second item and after all item still get valid ActualWidth and Height...

    So I move lv_Content.ItemsSource to Loaded() Event, then that will fix this problem.

    • Marked as answer by THKAW Wednesday, November 19, 2014 3:42 AM
    Wednesday, November 19, 2014 3:42 AM
  • Hi THKAW,

    Well Done!

    It is really very kind of you to share the solution to us, it will help the others who meet the same questions as you.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 19, 2014 4:33 AM
    Owner