[英]Efficient way to bind images to a grid-view from a collection - Windows 8 Metro
目前,我在單獨的頁面上有幾個Gridview,其中包含圖像,它們都可以工作,除了性能很差,有時還會導致應用灰屏。 有誰知道在gridview中顯示圖像的更有效方法?
這是C#上的綁定
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
PhotoCollection PassedCollection = (PhotoCollection)e.NavigationParameter;
pCollection = PassedCollection;
pageTitle.Text = pCollection.name;
itemGridView.ItemsSource = pCollection.photos;
}
這是XAML:
</Grid>
<GridView
x:Name="itemGridView"
Margin="10"
ItemsSource="{Binding}"
SelectionMode="None" IsItemClickEnabled="True" Grid.Row="1" Grid.RowSpan="3">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid MaximumRowsOrColumns="5"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Left" Width="200" Height="100" Margin="5,5,5,5">
<Border Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}">
<Image Stretch="UniformToFill" Source="{Binding Image}">
</Image>
</Border>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
不要將復雜類型作為導航參數傳遞。 這是一個常見的陷阱, 會導致您的應用從暫停狀態恢復后崩潰。 將照片集存儲在靜態類或其他內容中,如有必要,請在導航參數中傳遞一個鍵。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.