我尝试使用此代码下载图像:
void downloadImage(){
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri("http://mysite/image.png"));
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
//how get stream of image??
PicToIsoStore(stream)
}
private void PicToIsoStore(Stream pic)
{
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
var bi = new BitmapImage();
bi.SetSource(pic);
var wb = new WriteableBitmap(bi);
using (var isoFileStream = isoStore.CreateFile("somepic.jpg"))
{
var width = wb.PixelWidth;
var height = wb.PixelHeight;
Extensions.SaveJpeg(wb, isoFileStream, width, height, 0, 100);
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是:如何获得图像流?
谢谢!
有没有办法在一个TextBlock中组合静态文本和绑定?因为StringFormat在Windows Phone 7中不起作用.我试试
<TextBlock Text="{Binding strAudioArtistName, StringFormat=StaticText: {0}}"/>
Run Code Online (Sandbox Code Playgroud)
但不要工作....
谢谢
有一种方法可以使用bing贴图将地址转换为坐标吗?
谢谢
我把TiltEffect.IsTiltEnabled
属性添加到了我的HubTile
:
<toolkit:HubTile toolkit:TiltEffect.IsTiltEnabled="True" Title="title" Message="This is message" x:Name="name" DisplayNotification="False" Source="pB.png" Tap="tap" />
Run Code Online (Sandbox Code Playgroud)
我还在页面的构造函数中将HubTile
类型添加到TiltableItems
集合中,每个:
public HubPage()
{
TiltEffect.TiltableItems.Add(typeof(HubtTile));
}
Run Code Online (Sandbox Code Playgroud)
但HubTile没有倾斜效果....
谢谢!
我需要在Download.file方法完成后调用Join方法.我试图添加await关键字,但它没有用
Thread myThread = new Thread(new ThreadStart(()=> await Download.file(uri)));
Thread myThread = new Thread(new ThreadStart(()=>Download.file(uri)));
myThread.Start();
myThread.Join();
class Download{
public static async void file(string url)
{
try
{
HttpWebRequest request;
HttpWebResponse webResponse = null;
request = HttpWebRequest.CreateHttp(url);
request.AllowReadStreamBuffering = true;
webResponse = await request.GetResponseAsync() as HttpWebResponse;
Stream responseStream = webResponse.GetResponseStream();
using (StreamReader reader = new StreamReader(responseStream))
{
string content = await reader.ReadToEndAsync();
}
webResponse.Close();
}
catch (Exception ex) {
Debug.WriteLine(ex.Message);
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢
嗨,我尝试从列表框中删除所有元素:这是我的简单列表框:
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}" Name="listbox" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17" >
<!--Replace rectangle with image-->
<Image Source="{Binding Img}" />
<StackPanel Width="311">
<TextBlock Text="{Binding Pos}"
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试删除列表框的所有元素时,错误是:
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.dll
System.InvalidOperationException: Operation not supported on read-only collection.
at System.Windows.Controls.ItemCollection.ClearImpl()
at System.Windows.PresentationFrameworkCollection`1.Clear()
at aaaaa.MainPage.Button_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
private …
Run Code Online (Sandbox Code Playgroud) 我不明白错误在哪里...
using System.Xml.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace xmldow
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void clickBott(object sender, RoutedEventArgs e)
{
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri("http://example.net/ddd/my.xml"));
}
void client_DownloadStringCompleted(Object sender, DownloadStringCompletedEventHandler e)
{
throw new NotImplementedException();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
错误1'client_DownloadStringCompleted'没有重载匹配委托'System.Net.DownloadStringCompletedEventHandler'
谢谢