繁体   English   中英

WPF在图片框中显示来自HTTP请求的图像

[英]WPF Display image from http request in picturebox

我想显示来自URL的图像,下面是我的代码。 通过这种方式,我可以在本地显示任何图像,但是无法从远程服务器显示任何图像。 我在mainWindow xaml中的代码:

    <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; }

    }

怎么样....

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM