0

ThreadPool.QueueUserWorkItem() から画像をダウンロードする WPF アプリケーションがあります。UI には、画像がキャッシュされるはずのフォルダーをチェックする DispatcherTimer があり、見つかった場合は、2 つの Border 要素と Button 要素の背景としてそれらを表示することになっています。

ファイルが filePath にダウンロードされていることを確認でき、BitmapImage オブジェクトを作成するコードをステップ実行できますが、画面に何もレンダリングされていません。

関連するコードを以下に貼り付けます。

<Border x:Name="leftImage"
        BorderBrush="Transparent"
        BorderThickness="0"
        HorizontalAlignment="Left"
        Height="220"
        VerticalAlignment="Top"
        Width="99">
    <Button Template="{StaticResource LeftArrow}"
            Width="20"
            Height="20"
            HorizontalAlignment="Left"
            Margin="10,0,0,0" />
</Border>
<Border x:Name="rightImage"
        BorderBrush="Transparent"
        BorderThickness="0"
        HorizontalAlignment="Right"
        Height="220"
        VerticalAlignment="Top"
        Width="99"
        Grid.Column="2">
    <Button Template="{StaticResource RightArrow}"
            Width="20"
            Height="20"
            HorizontalAlignment="Right"
            VerticalAlignment="Center"
            Margin="0,0,10,0" />
</Border>
<Button x:Name="center"
        Grid.Column="1"
        HorizontalAlignment="Center"
        Style="{StaticResource BaseButtonStyle}"
        VerticalAlignment="Top"
        Width="400"
        Height="220" />

//ShowImage is being called via DispatcherTimer every 5 seconds
private void ShowImage(int p, int b)
        {
            if (p < 0 || p > Model.HomeCarouselItems.Count - 1) return;
            var filePath = //FilePath 
            if (File.Exists(filePath) && !Utils.IsFileLocked(new FileInfo(filePath)))
            {
                BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.BeginInit();
            bitmapImage.UriSource = new Uri(filePath,UriKind.Absolute);
            bitmapImage.EndInit();
            bitmapImage.Freeze();
                switch (b)
                {
                    case 1:
                        leftImage.Background = new ImageBrush() { ImageSource = bitmapImage };

                        break;
                    case 3:
                        rightImage.Background = new ImageBrush() { ImageSource = bitmapImage };

                        break;
                    case 2:
                        center.Content = new Image() { Source = bitmapImage };

                        break;
                }
            }


        }

誰かが見て、私がここで間違っていることを理解するのを手伝ってくれませんか..

4

1 に答える 1

-1

NotifyPropertyChanged() はプロパティでのみ機能します。

filePath に画像が見つからないと思います。そのため、何も表示されません。

于 2013-08-07T13:33:29.240 に答える