Tag: windows phone

MvvmCross从ViewModel事件导航

我从这里读到了“ViewModel to ViewModel navigation”和“View Model Lifecycle”: https : //github.com/MvvmCross/MvvmCross/wiki/ViewModel–to-ViewModel-navigation https://github.com/MvvmCross/ MvvmCross /维基/视图模型,生命周期 我可以使用Init()或Start()方法来初始化当前的ViewModel。 此外,我可以将参数从一个ViewModel传递到另一个ViewModel并在Init()方法中接收它。 所以我的问题是:当我创建Windows手机应用程序时,我使用了“NavigateTo”和“NavigateFrom”方法。 Init()类似于“NavigateTo”。 但我没有找到mvvmcross中“NavigateFrom”方法的替代方法,当我通过“关闭(此)”或使用Windows手机上的后退按钮“返回”时,我不知道如何重新加载数据。 你能暗示我吗? 提前致谢! 更新 我发现Messenger(MvvmCross插件)可以帮助我通知第一个ViewModel,当另一个第二个ViewModel更改了数据时(例如将一个项目添加到一个集合中)。 因此,当第二个ViewModel添加一个新项时,首先ViewModel重新加载OnCollectionChanged(CollectionChangedMessage obj)方法中的数据。 Stuart展示了如何在NPlus1DaysOfMvvmCross / N-13-CollectABull-Part2中使用此插件。 链接到这里: https : //github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/N-13-CollectABull-Part2

如何检测WP8中是否播放背景音乐?

如果您知道如果您的应用程序在未经用户同意的情况下停止当前正在播放的音乐,则在您知道无法通 我确实在这里看到了这个可能适用于WP7应用程序的问题,但它显然不适用于WP8。 我认为它不起作用,因为WP8操作系统不支持XNA(它只是向后兼容,如果您使用7.1开发应用程序)。 有没有人遇到过在WP8中检测背景音乐的解决方案。

Windows Phone 8.1 MediaComposition – 拼接video时音频太快

尝试将多个video连接在一起时遇到问题。 每当我合并2个或更多video时,音频以双倍速度播放,而video正常播放。 以下是代码。 我错过了什么吗? 我在测试时会得到相同的结果,但是克隆单个video或选择多个video。 我已经比较了这里的代码示例(我没有修剪)。 public static IAsyncOperation ConcatenateVideoRT([ReadOnlyArray]IStorageFile[] videoFiles, IStorageFolder outputFolder, string outputfileName) { return Task.Run(async () => { IStorageFile _OutputFile = await outputFolder.CreateFileAsync(outputfileName, CreationCollisionOption.GenerateUniqueName); MediaComposition _MediaComposition = new MediaComposition(); foreach (IStorageFile _VideoFile in videoFiles) { MediaClip _MediaClip = await MediaClip.CreateFromFileAsync(_VideoFile); _MediaComposition.Clips.Add(_MediaClip); _MediaComposition.Clips.Add(_MediaClip.Clone()); } TranscodeFailureReason _TranscodeFailureReason = await _MediaComposition.RenderToFileAsync(_OutputFile); if (_TranscodeFailureReason != TranscodeFailureReason.None) […]

如何防止Windows(手机)8.1通用应用程序中的锁屏?

有谁知道,如何防止Windows(手机)8.1通用应用程序中的锁屏? 在Windows Phone 8中,我使用过: PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; 有人有想法吗?

C#中的地理位置

我正在尝试开发一个应该像游戏一样的应用程序。 用户在城市中会有一些位置,他必须在每个位置做一些事情。 为了跟踪用户的位置,我尝试使用以下代码进行地理定位: Geolocator geolocator = new Geolocator(); //geolocator.DesiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.High; geolocator.DesiredAccuracyInMeters = 50; try { Geoposition geoposition = await geolocator.GetGeopositionAsync(TimeSpan.FromMilliseconds(500), TimeSpan.FromSeconds(1)); textLatitude.Text = “Latitude: ” + geoposition.Coordinate.Latitude.ToString(“0.0000000000”); textLongitude.Text = “Longitude: ” + geoposition.Coordinate.Longitude.ToString(“0.0000000000”); textAccuracy.Text = “Accuracy: ” + geoposition.Coordinate.Accuracy.ToString(“0.0000000000”); } 使用以下方法获取坐标,我试图测试设备是否将使用以下代码正确定位我的位置: if( Math.Abs(geoposition.Coordinate.Latitude – 45.3285) < 0.001 ){ if (Math.Abs(geoposition.Coordinate.Longitude – 14.4474) < 0.001) […]

将包含图像的流保存到Windows Phone 8上的本地文件夹

我目前正在尝试保存包含我从相机返回到本地存储文件夹的jpeg图像的流。 正在创建文件,但遗憾的是根本不包含任何数据。 这是我正在尝试使用的代码: public async Task SaveToLocalFolderAsync(Stream file, string fileName) { StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFile storageFile = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); using (IRandomAccessStream fileStream = await storageFile.OpenAsync(FileAccessMode.ReadWrite)) { using (IOutputStream outputStream = fileStream.GetOutputStreamAt(0)) { using (DataWriter dataWriter = new DataWriter(outputStream)) { dataWriter.WriteBytes(UsefulOperations.StreamToBytes(file)); await dataWriter.StoreAsync(); dataWriter.DetachStream(); } await outputStream.FlushAsync(); } } } public static class UsefulOperations […]

StorageFile比IsolatedStorageFile慢50倍

当我发现在我的Lumia 920上运行的应用程序的WP7版本加载数据的速度是在同一设备上运行的WP8版本的2倍时,我只是对多个算法进行基准测试以找到加载我应用程序中所有数据的最快方法。 我编写了以下独立代码来测试WP8的StorageFile和WP7的IsolatedStorageFile的性能。 为了澄清标题,这里是我做的初步基准测试结果,读取50个20kb和100kb的文件: 有关代码,请参阅下文 更新 在做了几个小时的基准测试和一些有趣的结果之后,让我重新解释一下我的问题: 为什么await StreamReader.ReadToEndAsync()在每个基准测试中都比非异步方法StreamReader.ReadToEnd()更慢? (这可能已经在Neil Turner的评论中得到了回答) 使用StorageFile打开文件时似乎有很大的开销,但只有在UI线程中打开它时才会出现。 (请参阅方法1和3之间或5到6之间的加载时间的差异,其中3和6比等效的UI线程方法快10倍) 有没有其他方法来读取可能更快的文件? 更新3 好吧,现在有了这个更新我添加了10个算法,重新使用每个以前使用的文件大小和使用的文件数量的每个算法。 这次每个算法运行10次。 因此,excel文件中的原始数据是这些运行的平均值。 由于现在有18种算法,每种算法都有4种文件大小(1kb,20kb,100kb,1mb),每种文件分别为50,100和200个文件(18 * 4 * 3 = 216),总共有2160个基准测试运行,总时间为95分钟(原始运行时间)。 更新5 添加了基准测试25,26,27和ReadStorageFile方法。 不得不删除一些文本,因为post有超过30000个字符,这显然是最大的。 使用新数据,新结构,比较和新图表更新了Excel文件。 代码: public async Task b1LoadDataStorageFileAsync() { StorageFolder data = await ApplicationData.Current.LocalFolder.GetFolderAsync(“benchmarks”); data = await data.GetFolderAsync(“samplefiles”); //b1 for (int i = 0; i < filepaths.Count; i++) { […]

如何在Windows Phone中反序列化json数据?

最初我的json是格式的, “code”: 0, “message”: “success”, “students”: [ { “id”: “257633000000070001”, “name”: “hjeke”, “percentage”: 36, “type”: “Good”, }, { “id”: “257633000000073001”, “name”: “Second”, “percentage”: 4, “type”: “bad”, }] 所以我使用以下类使用Newtonsoft.json进行反序列化 [DataContract] public class students { [DataMember(Name = “code”)] public int Code { get; set; } [DataMember(Name = “message”)] public string Message { get; set; } [DataMember(Name = […]

删除Windows Phone C#app中的数组项,并且永远不会在下次应用启动时显示

我正在使用C#开发Windows Phone应用程序。 它在数组中有10000个元素。 我的程序sudo代码是这样的 Begin Get a random element from array Manipulate it Delete it End 应该从应用程序中透视删除该数组元素(即,我不应该在下一个应用程序启动时获取它) 如何轻松执行此任务。 请给我一些代码,以便我能够轻松理解。

不是从MainPage类编辑XAML文本框

我有MainPage类,我可以使用此代码编辑XAML文本框的内容 box1.Text = “”; 但是,尝试从另一个类编辑文本框时,以下代码将不起作用 MainPage.box1.Text = “”; 错误是“非静态字段,方法或属性’类需要一个对象引用.MainPage.box1’我尝试过所有的东西,比如制作静态函数和在另一个类中创建新的MainPage对象,但没有任何工作