2014-09-15 4 views
0

XAML을 사용하여 GridView에 바인딩하려는 비디오 목록이 있습니다. 나는 다음과 같은 코드로 프로그래밍하는을했고, 그것은 노력하고 있습니다 :GridView를 XAML의 비디오 목록에 바인딩하는 방법?

private async void pageRoot_Loaded(object sender, RoutedEventArgs e) { 
    IList<string> fileTypeFilter = new List<string> { ".avi", ".mkv", ".mp4" }; 
    QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter); 
    queryOptions.FolderDepth = FolderDepth.Deep; 
    queryOptions.IndexerOption = IndexerOption.UseIndexerWhenAvailable; 

    StorageFileQueryResult videoFileQuery = KnownFolders.VideosLibrary.CreateFileQueryWithOptions(queryOptions); 
    IReadOnlyList<StorageFile> dataSource = await videoFileQuery.GetFilesAsync(); 

    videoGridView.ItemsSource = dataSource; //Yep, that works :) 
} 

Howevery,이 XAML에서 바인딩을 가지고 싶습니다. 그래서 XAML의의 GridView를 변경하고, 상기 코드의 마지막 줄 제거 :

<GridView x:Name="videoGridView" Grid.Row="1" ItemsSource="{Binding dataSource}"/> 

만이 지금의 GridView가 비어 있습니다.

이 작업을 수행하려면 어떻게해야합니까?

답변

1

그냥 2 번 변경하십시오. 첫째, 대신 게시 된 코드의 마지막 줄에, 그런 다음 Grid

<GridView x:Name="videoGridView" Grid.Row="1" ItemsSource="{Binding}"/> 
로 변경

this.DataContext = dataSource; 

을 다음 쓰기

0

ObservableCollection < StorageFile> 원본에 바인딩하려고합니다.

관련 문제