Tag: windows runtime

什么取代了WinRT中的CommandManager?

我开始使用Metro风格的应用程序(我知道我们不应该把它称为Metro,但我永远不会记得它应该被称为…),我正在实现一个用于MVVM的DelegateCommand类。 在WPF中, ICommand.CanExecuteChanged事件通常实现如下: public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } 但WinRT中不存在CommandManager类……还有其他的东西吗? 或者我们应该自己明确地触发这个事件?

“System.DateTime”不是有效的Windows运行时参数类型

我正在使用C#类,它在我的Windowsapp store应用程序(C#)中运行得非常好。 但是当我尝试在Windows运行时Compenent中使用它时,我收到以下错误: Calculator.Calculate(System.DateTime)’具有’System.DateTime’类型的参数’dateTime’。 “System.DateTime”不是有效的Windows运行时参数类型。 类中的示例对象: public DateTime Calculate(DateTime dateTime) { int dayNumberOfDateTime = ExtractDayNumber(dateTime); int sunRiseInMinutes = CalculateSunRiseInternal(tanSunPosition, differenceSunAndLocalTime); return CreateDateTime(dateTime, sunRiseInMinutes); } 我怎样才能解决这个问题? 问题是什么?

如何在Metro GridView中使用不同的布局?

我正在写一个Windows 8 Metro应用程序。 我正在尝试使用三个组绘制GridView。 我希望其中一个组以不同于其他组的方式布置项目。 我之前在WPF中使用过选择器,所以我认为这是一条很好的路线。 所以我尝试了GroupStyleSelector,我在MSDN上找到了这个例子 : public class ListGroupStyleSelector : GroupStyleSelector { protected override GroupStyle SelectGroupStyleCore(object group, uint level) { return (GroupStyle)App.Current.Resources[“listViewGroupStyle”]; } } 所以我改编/扩展了适合我的东西: CS: public class ExampleListGroupStyleSelector : GroupStyleSelector { public ExampleListGroupStyleSelector () { OneBigItemGroupStyle = null; NormalGroupStyle = null; } public GroupStyle OneBigItemGroupStyle { get; set; } public GroupStyle NormalGroupStyle […]

Reactive Extensions:批量处理事件+在每批之间添加延迟

我有一个应用程序,在某些时候几乎同时引发了1000个事件。 我想要做的是将事件批处理为50个项目的块并开始每10秒处理一次。 在开始新的批处理之前,无需等待批处理完成。 例如: 10:00:00: 10000 new events received 10:00:00: StartProcessing (events.Take(50)) 10:00:10: StartProcessing (events.Skip(50).Take(50)) 10:00:15: StartProcessing (events.Skip(100).Take(50)) 任何想法如何实现这一目标? 我认为Reactive Extensions是要走的路,但其他解决方案也是可以接受的。 我试着从这里开始: var bufferedItems = eventAsObservable .Buffer(15) .Delay(TimeSpan.FromSeconds(5) 但注意到延迟没有像我希望的那样工作,而是所有批次同时开始,但延迟了5秒。 我也测试了Window方法,但我没有发现任何行为上的差异。 我想Window中的TimeSpan实际上意味着“记录在接下来的10秒内发生的每一个事件: var bufferedItems = eventAsObservable .Window(TimeSpan.FromSeconds(10), 5) .SelectMany(x => x) .Subscribe(DoProcessing); 我正在使用Rx-Main 2.0.20304-beta。

获取UWP app文件夹中的所有文件

对于UWP,可以轻松地将app本地文件夹中的所有文件作为: IReadOnlyList files = await ApplicationData.Current.LocalFolder.GetFilesAsync(); 您现在可以迭代文件列表,甚至可以获得有关各个文件的更多信息。 我想为app文件夹添加类似的all-file-getter,例如,考虑存储app * .png文件的/ Assets文件夹。 具有已知名称的单个文件没有问题; 我可以很容易地将它称为: StorageFile.GetFileFromApplicationUriAsync(new Uri(@”ms-appx:///Assets/StoreLogo.png”)) 因此,我的问题是,在app文件夹中获取所有文件是否类似,例如/ Assets文件夹? 逻辑上,它应该类似于StorageFile.GetFilesFromApplicationFolderUriAsync(new Uri(@”ms-appx:///Assets”))但不知道是否存在上面显示的LocalFolder的等价物。

ListViewItem IsSelected Binding – 适用于WPF,但不适用于WinRT

我正在尝试将ListViewItem的IsSelected属性绑定到ViewModel中的属性。 它在WPF中工作正常,但在Windows RT中,IsSelected属性永远不会被设置。 public class Item : INotifyPropertyChanged { private readonly string name; private bool isSelected; public event PropertyChangedEventHandler PropertyChanged; public bool IsSelected { get { return isSelected; } set { isSelected = value; RaisePropertyChanged(“IsSelected”); } } public string Name { get { return name; } } public Item(string name) { this.name = name; } […]

用于WPF的Windows 8现代UI样式

我希望我的WPF应用看起来像WinRT应用程序: 是否有任何现成的样式或控件可用于WPF,让我们实现这一目标?

UWP编译绑定x:Bind产生内存泄漏

在开发UWP应用程序时,我最近发现了很多内存泄漏,导致我的页面被GC收集。 我的页面上有一个ContentPresenter,如: 删除内容后,或用动态{Binding}替换它 – 当我从中导航时收集页面。 否则它会留在内存中。 是错误还是我做错了什么? 有没有办法释放并清除导航时的所有绑定? 更新:这似乎是微软内部已知的问题,如此处所述。 但是,就我自己的测试/应用程序使用情况而言,x:Bind保留的数据仍会在一段时间后收集,例如,当您导航到相同的页面或创建相同的控件一段时间。 我可以看到创建了新对象,但在某些时候收集了旧对象。 所以对我而言,它似乎并不是导致内存不足的严重问题,它只是不允许像动态绑定那样快速收集对象。

将包含图像的流保存到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 […]

在metro应用程序中使用MostRecentlyUsedList时未经授权的例外情况

我正在使用C#处理商店应用程序。 我正在使用StorageApplicationPermissions.MostRecentlyUsedList来加载本地Epub文件。 将这些文件作为存储文件获取后。 string EpubPathToken= Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file); StorageFile file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(EpubPathToken); Extraction(file); 使用ApplicationData将Epub文件解压缩为Zip to Package文件夹时,我收到了一个未授权的执行。 这是错误的屏幕截图 为什么因为如果我使用像图库这样的KnownFolders使用相同的代码,那么提取工作正常。 任何人都可以给我任何想法吗?