Tag: windows phone 8

在Windows Phone 8中获取UI调度程序

我一直在开发一个消耗Windows运行时组件(WRC)的Windows Phone应用程序。由非UI线程访问的function需要使用访问Windows Phone应用程序的回调。 void WControlPointCallback::OnListChange(char *pFriendlyName) { // Callback function to access the UI pCallBack->AlertCaller(“Message”); } 最初没有使用Dispatcher它扔了 Platform::AccessDeniedException 。 然后我提到了这个 , 这个和这个 。 我试图从UI获取Dispatcher。 var dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher; 它抛出了System.AccessViolationException 。然后我用了 pDispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher; 在C ++代码(WRC)中。但是这也抛出了Platform::AccessDeniedException 。 如何在Windows Phone中获取Dispatcher for UI?

无法从WP8上的SD卡上的SQLite DB中检索数据

我在控制台应用程序中使用System.Data.SQLite创建了一个SQLite数据库。 然后我把它移到了Windows Phone的SD卡上。 我按照这些说明为我的WP8应用添加了SQLite支持: https : //github.com/peterhuene/sqlite-net-wp8 我找到了DB文件并打开它,如下所示: ExternalStorageFile file = null; IEnumerable storageDevices = await ExternalStorage.GetExternalStorageDevicesAsync(); foreach (ExternalStorageDevice storageDevice in storageDevices) { try { file = await storageDevice.GetFileAsync(“northisland.nztopomap”); } catch { file = null; } if (file != null) break; } SQLiteConnection conn = new SQLiteConnection(“Data Source=” + file.Path + “;Version=3;Read Only=True;FailIfMissing=True;”); SQLiteCommand command […]

CookieException与CookieContainer:Cookie的“路径”部分无效

我正在尝试设置cookie的路径,但我总是收到错误: CookieException: The ‘Path’=’/applogin’ Cookie CookieException: The ‘Path’=’/applogin’部分无效。 代码看起来像这样: Cookie newCookie = new Cookie(“JSESSIONID”, session.SessionId, “/applogin”, “domain.com”); newCookie.Secure = true; webRequest.CookieContainer.Add(new Uri(@”https://domain.com”), newCookie); 那个例外是在最后一行抛出……有人能指出我正确的方向吗?

依赖属性更改了回调 – 多次触发

我想听听DependencyProperty的变化。 此代码有效,但每次使用CustomControl重新加载页面后都会调用多次回调方法… public partial class CustomControl : UserControl { public CustomControl() { InitializeComponent(); } public bool IsOpen { get { return (bool)GetValue(IsOpenProperty); } set { SetValue(IsOpenProperty, value); } } public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(“IsOpen”, typeof(bool), typeof(CustomControl), new PropertyMetadata(IsOpenPropertyChangedCallback)); private static void IsOpenPropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e) { Debug.WriteLine(“Fire!”); } } 更新 视图模型 private bool […]

如果有条件,是否可以使用Task ?

在Windows Phone 8中,我有方法public async Task authentication() 。 该函数的返回类型是bool但是当我尝试在if条件中使用其返回值时,错误表示无法将Task转换为bool 。 public async Task authentication() { var pairs = new List<KeyValuePair> { new KeyValuePair (“user”, _username), new KeyValuePair (“password”, _password) }; var serverData = serverConnection.connect(“login.php”, pairs); RootObject json = JsonConvert.DeserializeObject(await serverData); if (json.logined != “false”) { _firsname = json.data.firsname; _lastname = json.data.lastname; _id = json.data.id; _phone = […]

在Windows Phone上启动pdf文件时出现System.Runtime.InteropServices.COMException

我正在尝试使用以前在其他应用上使用的以下工作代码打开pdf文件, 但是这次当流程命中这行时我得到System.Runtime.InteropServices.COMException:Windows.System.Launcher.LaunchFileAsync(pdffile); 这个例外是什么意思以及如何摆脱它? 请注意,如果不关心此exception(禁用它), 该文件仍然无法打开。 请注意:该文件存在于我的隔离文件夹中(使用wpowertool检查), 我尝试了2个不同的文件,所以它不应该是文件损坏的问题。 public void openFile(string options) { System.Diagnostics.Debug.WriteLine(“options: ” + options); string optVal = JsonHelper.Deserialize(options)[0]; asyncOpen(optVal); } public async Task asyncOpen(string filename) { filename = filename.Substring(2, filename.Length – 2); filename = filename.Replace(“//”, “/”).Replace(“/”, “\\”); Windows.Storage.StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; Debug.WriteLine(“local: ” + local.Path); Windows.Storage.StorageFile pdffile = await local.GetFileAsync(filename); Debug.WriteLine(“pdffile: ” + […]

HttpWebRequest BeginGetResponse回调未在WP8上触发(在WP7上工作)

我遇到的问题是以前的应用程序没有使用WP8,它在WP7上运行得很好。 这是我用于http请求的代码: public void SendMessage() { request = WebRequest.Create(uri) as HttpWebRequest; request.Method = “POST”; request.AllowReadStreamBuffering = true; request.ContentType = “application/octet-stream”; try { // get device info String deviceInfo = String.Format(“platform,{0};os,{1};width,{2};height,{3};dpi,{4};”, Config.PLATFORM_NAME, Environment.OSVersion.Version.ToString(), System.Windows.Application.Current.Host.Content.ActualWidth.ToString(), System.Windows.Application.Current.Host.Content.ActualHeight.ToString(), 96); request.Headers[“X_MX_DEVICE_INFO”] = deviceInfo; } catch (Exception) {} request.BeginGetRequestStream(new AsyncCallback(ProcessRequestStream), null); } private void ProcessRequestStream(IAsyncResult asyncResult) { if (!message.IsCancelled()) { try […]

如何通过拉下物品来刷新?

对于这个问题有很多答案,但是,正如我所看到的,所有这些都是关于在底部获取旧项目。 这个解决方案 void resultList_ItemRealized(object sender, ItemRealizationEventArgs e) { if (!_viewModel.IsLoading && resultList.ItemsSource != null && resultList.ItemsSource.Count >= _offsetKnob) { if (e.ItemKind == LongListSelectorItemKind.Item) { if ((e.Container.Content as TwitterSearchResult).Equals(resultList.ItemsSource[resultList.ItemsSource.Count – _offsetKnob])) { _viewModel.LoadPage(_searchTerm, _pageNumber++); } } } } 是在向下滚动时获取物品。 如何在顶部获取新的内容(底部不是更旧的内容)? 如何知道用户是否向上滚动LongListSelector

wp8的任务队列?

在wp8中对复杂任务进行排队的正确方法是什么? 任务包括以下内容: 通过更新模型变量显示ProgressIndicator 获取或存储数据到wcf服务( UploadStringAsync ) 使用UploadStringCompleted的结果更新潜在的数据绑定模型。 通过更新模型变量隐藏ProgressIndicator 目前我一直在使用一个拥有命令对象队列的类,运行一个在添加项目时启动的线程(如果它尚未运行)。 但是,我有等待代码停止运行的任务或子任务的问题。 以前我曾经使用异步等待,但是行为的几个级别变得越来越难以预测。 我想要的是能够创建和排队命令对象的主线程。 命令对象应该一次运行一个,而不是在前一个完全完成之前启动一个新对象。 如果需要,命令对象应该能够使用调度程序访问主线程。

将上下文菜单添加到WP8浏览器控件

当用户在网页上的链接上执行保持手势时,我尝试附加上下文菜单。 我在网上搜索过,发现了一些建议 if (webBrowser.IsScriptEnabled) { webBrowser.InvokeScript(“execScript”, “function eventListener(evt){ if (evt.type == ‘MSPointerDown’) { gestureHandler.addPointer(evt.pointerId); return; } if (evt.detail & evt.MSGESTURE_FLAG_END) { window.external.notify(evt.srcElement.tagName);}}”); webBrowser.InvokeScript(“execScript”,”document.addEventListener(‘MSGestureHold’, eventListener, false); document.addEventListener(‘MSPointerDown’, eventListener, false); gestureHandler = new MSGesture(); gestureHandler.target = document.body;”); } 但是第二个execScript引发了这个错误 System.SystemException was unhandled by user code HResult=-2146233087 Message=An unknown error has occurred. Error: 80020101. Source=Microsoft.Phone.Interop StackTrace: at Microsoft.Phone.Controls.NativeMethods.ValidateHResult(Int32 […]