2013-12-16 55 views
0

我想從URL顯示圖像,下面是我的代碼。通過這種方式,我可以在本地顯示任何圖像,但從遠程服務器不工作。 我的主窗口中的XAML代碼: WPF在picturebox中顯示來自http請求的圖像

<ScrollViewer Name="contentScrolViewer" Grid.Row="1"> 
     <ItemsControl Name="ImageList" SnapsToDevicePixels="True"> 
      <ItemsControl.ItemsPanel> 
       <ItemsPanelTemplate> 
        <WrapPanel IsItemsHost="True" Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollContentPresenter}}}" > 
        </WrapPanel> 
       </ItemsPanelTemplate> 
      </ItemsControl.ItemsPanel> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <StackPanel Height="311" Width="171" HorizontalAlignment="Left" Margin="10"> 
         <Grid Height="225" Margin="0.5,0"> 
          <Rectangle Fill="#FF0B0B1F" Stroke="Black" StrokeThickness="0"/> 
          <Image Source="{Binding image}" Width="171" Height="311" Stretch="Fill"/> 
         </Grid> 
         <Rectangle Fill="#FF211F1A" Stroke="Black" Height="85" StrokeThickness="0" Margin="0,0,0.5,0"/> 
        </StackPanel> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl> 
    </ScrollViewer> 
</Grid> 

我在mainWindow.xaml.cs代碼

public partial class MainWindow : Window 
    { 

     public MainWindow() 
     { 
      InitializeComponent(); 
      List<ImageItems> items = new List<ImageItems>(); 
      items.Add(new ImageItems() { image = "http://diyaotheos.files.wordpress.com/2010/03/avatar_wallpaper_by_nyah86.png" }); 
      ImageList.ItemsSource = items; 
     } 
    } 
    public class ImageItems 
    { 
     public String image { get; set; } 

    } 
+0

上面的代碼工作(我使用WPF 4.5)。是否有可能存在網絡問題?嘗試連接到'Image.ImageFailed'事件。 –

+0

什麼破解:)我有我的互聯網速度問題。感謝您的提示兄弟。 –

回答

0

如何....

<Image Source="http://www.wpclipart.com/recreation/games/chess/chess_set_1/chess_piece_white_knight_T.png" /> 
+0

謝謝,我解決了它。問題只是在我的互聯網下載速度。而且,我正在使用可綁定的源代碼。無論如何謝謝。 –

相關問題