metro中访问WCF并加载一个图片

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            List<ServiceReference1.Pic> jokes = await this.getFileContentAsync();
            ImageBrush imageBrush = new ImageBrush();
            imageBrush.ImageSource = new BitmapImage(new Uri(jokes[4].URL));
            this.image1.Source = imageBrush.ImageSource;
        }
        private async Task<List<ServiceReference1.Pic>> getFileContentAsync()
        {
            ServiceReference1.JokeClient client = new ServiceReference1.JokeClient();
            var query = await client.GetPicListAsync(10);
            List<ServiceReference1.Pic> jokes = query.ToList();
            return jokes;
        }

如果这里加载的是本地的图片,请这样写

string filename="ms-appx:///Images/num.png";

来指定一个图片文件的位置,这里的ms-appx:///指的就是程序的根路径

你可能感兴趣的:(metro)