0

我正在将 Windows 存储中的图像绑定到Image我的视图中的控件这里是一些代码:(Images是一个ObservableCollection

 // 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...

4

1 回答 1

1

大概是这样的:RaisePropertyChanged(() => imagesVM.Logo);

尝试更改您的imagesVM类型以在设置时引发其自己的属性更改通知Logo

于 2013-01-03T03:31:22.553 回答