Tag: windows phone 7

IsolatedStorageFileStream上不允许操作。 错误

我有孤立存储的问题。 这是我的代码: List data = new List(); using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream isoStream = isoStore.OpenFile(“Notes.xml”, FileMode.OpenOrCreate)) { XmlSerializer serializer = new XmlSerializer(typeof(List)); data = (List)serializer.Deserialize(isoStream); } } data.Add(new Notes() { Note = “hai”, DT = “Friday” }); return data; 错误:IsolatedStorageFileStream上不允许操作。 在 using (IsolatedStorageFileStream isoStream = isoStore.OpenFile(“Notes.xml”, FileMode.OpenOrCreate))

使用WebClient / HttpWebRequest – WP7从https检索XML

我正在尝试从服务器检索XML文档并将其作为字符串存储在本地。 在桌面.Net我不需要,我只是做了: string xmlFilePath = “https://myip/”; XDocument xDoc = XDocument.Load(xmlFilePath); 但是在WP7上会返回: Cannot open ‘serveraddress’. The Uri parameter must be a relative path pointing to content inside the Silverlight application’s XAP package. If you need to load content from an arbitrary Uri, please see the documentation on Loading XML content using WebClient/HttpWebRequest. 所以我从这里开始使用WebClient / HttpWebRequest示例,但现在它返回: The […]

将基于事件的模式转换为异步CTP模式

_fbClient.GetCompleted += new EventHandler(OnFetchPageNotification); _fbClient.GetAsync(_kNotificationPath, new Dictionary { { “access_token”, _kPageAccessToken } }); 如何将上面的代码转换为wp7中的等待代码: object = await _fbClient.GetAsync(_kNotificationPath, new Dictionary { { “access_token”, _kPageAccessToken } }); 我也有CTP安装和任务并行库。

如何检测另一个音频是否在后台播放? (Windows Phone 7)

我的一个应用程序最近未通过认证,因为:“我的应用程序停止播放背景音乐而不询问用户何时播放某些音乐”。 现在的问题是:我们如何检测背景中是否有音乐播放? 问候

过滤ObservableCollection?

当我将ListBox直接绑定到ObservableCollection时,我得到了我的ListBox中显示的实时更新,但是只要我在混合中添加其他LINQ方法,我的ListBox就不再被告知对ObservableCollection的任何更改。 在这里,让我举一个例子来说明; public partial class MainPage : PhoneApplicationPage { ObservableCollection Words = new ObservableCollection(); public MainPage() { InitializeComponent(); listBox1.ItemsSource = Words; } private void AddButton_Click(object sender, RoutedEventArgs e) { Words.Add(DateTime.Now.ToString()); } } 在这里,我向一个简单的页面添加了一个Button和一个ListBox,然后单击该按钮使新项目立即出现在ListBox中。 但是,如果我改变了 listBox1.ItemsSource = Words; 至 listBox1.ItemsSource = Words.Where(w => w.Contains(“:”)); ListBox不再更新。 如何在我的ObservableCollection和ListBox之间添加“filter”,并且仍然可以在不必再次设置.ItemsSource的情况下进行更新?

如何在c#中使用HttpClient中的凭据?

使用HttpClient类访问Delicious API时,我遇到了一些问题。 我有以下代码: try { const string uriSources = “https://api.del.icio.us/v1/tags/bundles/all?private={myKey}”; using (var handler = new HttpClientHandler { Credentials = new NetworkCredential(“MyUSER”, “MyPASS”) }) { using (var client = new HttpClient(handler)) { var result = await client.GetStringAsync(uriSources); } } } catch (Exception ex) { MessageBox.Show(ex.Message, “ERROR…”, MessageBoxButton.OK); } 运行上面的代码时,我得到以下内容:响应状态代码不表示成功:401(未授权)。 那么,我怎么能得到这个工作? 可能吗? 提前致谢 问候!

如何使用RestSharp发送请求

我试图使用RestSharp客户端POST请求,如下所示我将Auth Code传递给以下函数 public void ExchangeCodeForToken(string code) { if (string.IsNullOrEmpty(code)) { OnAuthenticationFailed(); } else { var request = new RestRequest(this.TokenEndPoint, Method.POST); request.AddParameter(“code”, code); request.AddParameter(“client_id”, this.ClientId); request.AddParameter(“client_secret”, this.Secret); request.AddParameter(“redirect_uri”, “urn:ietf:wg:oauth:2.0:oob”); request.AddParameter(“grant_type”, “authorization_code”); request.AddHeader(“content-type”, “application/x-www-form-urlencoded”); client.ExecuteAsync(request, GetAccessToken); } } void GetAccessToken(IRestResponse response) { if (response == null || response.StatusCode != HttpStatusCode.OK || response.Data == null || string.IsNullOrEmpty(response.Data.access_token)) { […]

Silverlight旋转和缩放位图图像以适合矩形而不进行裁剪

我需要旋转一个WriteableBitmap并在它被裁剪之前向下或向上缩放。 我的当前代码将旋转,但如果高度大于宽度,则会裁剪边缘。 我想我需要扩展? public WriteableBitmap Rotate(WriteableBitmap Source, double Angle) { RotateTransform rt = new RotateTransform(); rt.Angle = Angle; TransformGroup transform = new TransformGroup(); transform.Children.Add(rt); Image tempImage2 = new Image(); WriteableBitmap wb; rt.CenterX = Source.PixelWidth / 2; rt.CenterY = Source.PixelHeight / 2; tempImage2.Width = Source.PixelWidth; tempImage2.Height = Source.PixelHeight; wb = new WriteableBitmap((int)(Source.PixelWidth), Source.PixelHeight); tempImage2.Source = Source; […]

在引用中找不到System.Drawing.dll

我有一个奇怪的问题。 我正在使用Visual Studio 2010 Express for Windows Phone并想要引用System.Drawing.dll。 我在项目中右键单击“引用”并单击“添加引用…”,但是,我在.NET选项卡下找不到System.Drawing.dll。 有什么想法吗? 谢谢! 飞

一个超级简单的MVVM-Light WP7样本?

我正在寻找一个样本,以最轻微的方式演示以下内容: 一个调用基于SOAP的Web服务的模型; 定期轮询以获取最新值(假设SOAP服务返回一个布尔值)。 该模型还应支持调用更改服务器上布尔值的SOAP方法。 一个ViewModel,它允许底层布尔值绑定到View中的控件(例如,复选框)。 具有上述复选框控件的视图绑定到基础布尔值。 根据轮询间隔,复选框将随服务器状态的变化而更新。 如果单击该复选框,则会将事件分派给模型,从而导致服务器更新。 最好这个样本可以在Windows Phone 7上运行,但是在紧要关头我会对支持SL3的东西感到满意(不允许使用SL4命令路由)。 我正在努力了解如何让MVVM-Light为我工作,我怀疑专家可以很快地编写样本代码…我也怀疑这是很多应用程序的相当常见的模式。