从存储加载图像后无法更新视图

时间:2013-01-02 23:07:05

标签: xaml binding windows-8 winrt-xaml

我将视图中的图像从Windows存储绑定到Image控件 这是一些代码:(ImagesObservableCollection

 // Loading images from storage
        foreach (var imagesVM in Images)
        {
            var img = new BitmapImage();
            var tmp = await ImageHelpers.LoadImageFromStorageAsync(
                imagesVM.name);
            if (tmp != null)
            {
                img.SetSource(tmp);
                imagesVM.Logo = img;
                RaisePropertyChanged(() => imagesVM.Logo);
                RaisePropertyChanged(() => Images);
            }
        }

如果找不到图像,我的LoadImageFromStorageAsync方法将返回null。

我的问题是我的视图在加载图像时没有更新,如果我拖放元素,元素更新和图像显示,这是我的绑定:

 <StackPanel Orientation="Horizontal">
            <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}">
                <Image Source="{Binding Logo, Mode=TwoWay}" Stretch="UniformToFill" />
            </Border>
            <StackPanel Margin="20,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Text="{Binding Brand}"/>
                <TextBlock Text="{Binding Name}" Margin="0,5,0,0"/>
            </StackPanel>
        </StackPanel>

绑定效果很好,因为它在更新时显示(当我回去然后重新打开此页面时)

更奇怪的是,我的图像有时会显示出来......

有什么猜测?我想这是RaisePropertyChanged ...

1 个答案:

答案 0 :(得分:1)

可能是这样的:RaisePropertyChanged(() => imagesVM.Logo);

设置imagesVM时,请尝试更改Logo类型以提升自己的属性更改通知。

相关问题