FlipView:如何将Collection 绑定为ItemsSource
是否有一种智能方法来绑定包含要在FlipView
显示的图像的URL的Collection
?
或者我是否必须在Collection
提供图像?
您可以使用将这些URL绑定到ItemTemplate
内的Image
Source
属性:
flipView.ItemsSource = imageUrls;
在FlipView中显示Bing图像的示例 。
我知道这个答案相当晚,但你也可以绑定到一组图像。 实现此目的的最佳方法是使用可观察的位图集合而不是集合。 在视图模型中,创建一个返回可观察位图集合的属性
// defines the binding property to the flipview private ObservableCollection _pictureGallery; public ObservableCollection PictureGallery { get { return _pictureGallery; } set { if (_pictureGallery != value) { _pictureGallery = value; onPropertyChanged("PictureGallery"); } } } // This defines the property change event public event PropertyChangedEventHandler PropertyChanged; private void onPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } }
在你的xaml中,你可以像这样定义你的flipview
注意:根据您要如何创建位图图像,您有一个文件流来设置BitmapImage的来源
BitmapImage BitImage = new BitmapImage(); BitImage.SetSource(stream);