0

I'm creating a Win 8 app in which I need to display loops of gifs to the user. The interesting thing is, I'm using this same datatemplate to display all sorts of image types, including png and jpg.

Is there a control that would do this? If not, what is the recommended way to go about achieving this functionality?

Thanks for any help!

4

1 回答 1

1

在动画 gif 中查看动画的一种方法是在 WebView 元素中呈现 gif。

将 gif 添加到项目并标记为内容。然后将WebView的源设置为gif

<Grid >
  <WebView Source='ms-appx-web:///Assets/spiral.gif'>
 </WebView>

</Grid>

注意:Webview 通过 IE 10 呈现内容,它不像其他元素那样具有交互性。有关更多详细信息,请参阅此 MSDN 文章

编辑

这是绑定到集合的一种方法。

class GifCollection : ObservableCollection<Uri> {
}



// in the view
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    var gifs = new GifCollection();

    gifs.Add(new Uri("http://i.imgur.com/eoNiq.gif"));
    gifs.Add(new Uri("ms-appx-web:///Assets/spiral.gif"));

    this.DataContext = gifs;

}

以及 XAML 中的数据模板

<ListBox ItemsSource='{Binding}'>
      <ListBox.ItemTemplate>
        <DataTemplate>
          <StackPanel>

             <!-- set the width, height, otherwise the WebView 
                  is not visible in the datatemplate -->
            <WebView Source='{Binding }'
                     Width='450'
                     Height='450'>

            </WebView>
          </StackPanel>

        </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>
于 2012-10-21T20:22:37.657 回答