Windows Phone Pivot 模拟 滑动Image Viewer 出现 0x8000ffff 异常,pivot0x8000ffff
Windows Phone Pivot 模拟 滑动Image Viewer 出现 0x8000ffff 异常,pivot0x8000ffff
简介:App有多张图片需要展示,打算做一个 类似于 “图片”里面可以滑动的 图片展示页面。
实现的方式有很多。选个简单的,直接用Pivot来模拟。
问题:
过程中出现了:0x8000ffff 异常!!!
我将 ObservableCollection<Uri> 绑定到 ItemTemplete,并且设置ItemSource时候
引发0x8000ffff 异常。完全没有头绪。
使用的代码:
代码如下:
数据
[csharp]
private ObservableCollection<Uri> _imageUris;
public ObservableCollection<Uri> ImageUris
{
get { return _imageUris; }
set
{
if (_imageUris != value)
{
_imageUris = value;
RaisePropertyChanged("ImageUris");
}
}
}
加载数据
[csharp]
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
UmengSDK.UmengAnalytics.onPageStart("ImageViewerPage");
if (PhoneApplicationService.Current.State.ContainsKey("images"))
{
object list;
if (PhoneApplicationService.Current.State.TryGetValue("images", out list))
{
ImageUris = list as ObservableCollection<Uri>;
}
}
Pivot.ItemSource = ImageUris;
}
XAML
[html]
<controls:Pivot Title="查看图片"
Name="Pivot" >
<controls:Pivot.ItemTemplate>
<DataTemplate >
<Image Source="{Binding}" />
</DataTemplate>
</controls:Pivot.ItemTemplate>
<controls:Pivot.HeaderTemplate>
<DataTemplate >
<Grid>
<TextBlock Margin="0,0,1,0"
TextWrapping="Wrap"
d:LayoutOverrides="Width, Height" />
</Grid>
</DataTemplate>
</controls:Pivot.HeaderTemplate>
</controls:Pivot>
解决问题:
1.找了2 3个小时,开始以为是StaticsResources的问题。网上有说法是绑定名字出错,但是经过检查,
没有错误!
2.然后找到这个文章
https://www.nachmore.com/2010/silverlight-why-do-i-get-0x8000ffff-when-using-writeablebitmap-on-an-element/
Silverlight: Why do I get 0x8000ffff when using WriteableBitmap on an Element
大概是讲:强迫系统去render看不到的控件,会仆街。
按照这个思路,我觉得应该讲BitmapImage加载了,再绑定。
3.那就先将BitmapImage下载来咯,WebClient??好像不太好
我找到这个方案:
https://blog.csdn.net/moxiaomomo/article/details/7907054
延迟加载BitmapImage
C# 改成这样:
[csharp]
public ObservableCollection<BitmapImage> Images { get; set; }
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
UmengSDK.UmengAnalytics.onPageStart("ImageViewerPage");
if (PhoneApplicationService.Current.State.ContainsKey("images"))
{
object list;
if (PhoneApplicationService.Current.State.TryGetValue("images", out list))
{
ImageUris = list as ObservableCollection<Uri>;
}
}
Images.Clear();
foreach (var uri in ImageUris)
{
BitmapImage bitmap = new BitmapImage();
bitmap.CreateOptions = BitmapCreateOptions.BackgroundCreation;
// 当图片下载完成并解码成功时,会触发ImageOpened
bitmap.ImageOpened += (s, ex) =>
{
// 添加到图片列表
Images.Add(s as BitmapImage);
};
// uri为远程文件地址
bitmap.UriSource = uri;
}
int index = int.Parse(NavigationContext.QueryString["index"]);
Pivot.SelectedIndex = index;
Pivot.ItemsSource = Images;
}
相关文章
- 暂无相关文章
用户评论