Tag: windows runtime

如何检测Windows 8何时进入睡眠或恢复状态

我有一个应用程序,可以保持与服务器的连接,但是如果用户离开并且平板电脑进入hibernate状态,我想优雅地处理断开连接,我还想在用户唤醒平板电脑时重新登录。 我已尝试将以下代码放入我的连接类中,但它们永远不会被解雇。 Application.Current.Suspending += this.OnAppSuspending; Application.Current.Resuming += this.OnAppResuming;;

如何在WinRT中使用INotifyPropertyChanged?

我是一个新手,只是学习DataContext和MVVM模型的基础知识。 我现在有一个网格绑定到一个实现INotifyPropertyChanged的视图模型对象,但是看起来UpdateSourceTrigger (所有WPF教程告诉我使用它)不适用于WinRT / Metro Style应用程序! 那我如何实现INotifyPropertyChanged呢? 我在这里的绳索尽头。 我花了将近一天的时间在最基本的应用程序示例上,只是在点击某些内容后尝试更新网格。 到目前为止,我设法做到这一点的唯一方法是创建一个全新的视图模型实例并重新分配我知道错误的DataContext 更新: 我取得了一些进展,但事情变得非常奇怪。 我有一个视图模型,带有一个通用的项目列表。 项目列表与PropertyChangedEventHandler连接。 如果我用新的集合替换整个集合,listview会更新。 model.Items = new List{ new DataItem{ Title = “new item” }}; 这导致具有上述项目的一个项目列表。 但是,如果我尝试添加项目,则没有任何反应 model.Items.Add(new DataItem{ Title = “added item” }); 我也尝试创建一个添加项目并专门解雇PropertyChanged的方法,但这也不起作用 这就是它变得奇怪的地方。 接下来我尝试了这段代码。 model.Items.Add(new DataItem { Title = “added item” }); model.Items = new List { new DataItem { Title […]

无法加载Windows.winmd

我从这里按照以下示例在Win32应用程序中使用WinRT API。 我添加了对System.Runtime和System.Runtime.InteropServices.WindowsRunTime的引用,但是当我添加对Windows.winmd的引用时 我收到以下错误: 错误1生成清单时出错。 无法加载文件或程序集’C:\ Program Files(x86)\ Windows Kits \ 8.1 \ References \ CommonConfiguration \ Neutral \ Windows.winmd’或其依赖项之一。 尝试加载格式不正确的程序。 我尝试使用不同的.NET框架和Visual Studio版本进行各种配置。 我该怎么办?

指向Windows 10 UWP时PostAsync抛出IRandomAccessStream错误

我正在将Windows 8.1应用程序移植到Windows 10 UWP,但调用PostAsync现在会抛出exception。 这个确切的代码在定位8.1时非常有效,但是当我以Windows 10 UWP为目标时,它会引发以下exception: This IRandomAccessStream does not support the GetInputStreamAt method because it requires cloning and this stream does not support cloning. 码 public async void TestPost() { var parameters = GetParameters(); var formattedData = new FormUrlEncodedContent(parameters); using (var clientHandler = new HttpClientHandler { Credentials = GetCredentials() }) { using (var […]

如何在Windows 8 Metro App中获取GridView.Selected项目的滚动位置

我正在使用代码选择gridview项目,所以我还需要我的gridview在选定项目的位置滚动,我尝试了GridView.ScrollintoPosition()但它无法正常工作。 有没有办法获得SelectedItem的Scroll位置 ,以便我可以使用scrollViewer1.ScrollToHorizo​​ntalOffsetWithAnimation()滚动它

Windows 8:如何使用内置的墨水function撤消和重做墨水?

基于microsoft的简化墨迹示例,我在我的应用程序中实现了墨迹代码: http : //code.msdn.microsoft.com/windowsapps/Input-simplified-ink-sample-11614bbf/view/SourceCode 首先,我创建了一个保存操作数据的类(draw / delete / clear),如下所示: public enum eInkOperation { Draw, Delete, None } public class InkOperation { public InkStroke Stroke { get; set; } //requred for drawing from undo public eInkOperation Operation { get; set; } public InkOperation(InkStroke stroke, eInkOperation inkOperation) { Stroke = stroke.Clone(); //needs to be cloned for AddStroke […]

Windows 8.1中的MediaElement样式

如何更改样本MediaElement样式: 例如,我如何更改背景。 码:

Await阻止UI线程,网络相关

我在我的Windowsapp store应用中有这段代码,我点击了按钮。 但不知何故,当我在极少数情况下单击此按钮时,UI会冻结。 当我连接到比通常连接的Wi-Fi网络更远的Wi-Fi网络时,通常会发生这种情况。 考虑到我从互联网上下载RSS源,很可能与我使用async / await关键字有关。 如果我正确理解async / await的机制,UI线程根本不应该阻塞。 我在这里错过了什么吗? private async void Add_Click(object sender, RoutedEventArgs e) { AddButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed; DownloadProgressRing.Visibility = Windows.UI.Xaml.Visibility.Visible; DownloadProgressRing.IsActive = true; RssData rssData = App.Current.Resources[“rssData”] as RssData; Uri uri = FixUrl(RssUrl.Text); if (uri != null) { newRssFeed = new RssFeed(uri.ToString()); Task success = newRssFeed.RetrieveFeed(); if (await success) { […]

如何在GridView中的ListViewItemPresenter中更改SelectedBackground

我有一个Clickable-Gridview insde HubSection: 现在,每次我点击该集线器时,GridView(SelectedBackground)周围都会出现蓝色边框。 在LiveVisualTree中,它向我显示,边框来自GridViewItem内的“ListViewItemPresenter”控件。 因此,我从原始控件修改了样式并将其粘贴到Page.Resources标记中。 <ListViewItemPresenter ContentTransitions="{TemplateBinding ContentTransitions}" SelectionCheckMarkVisualEnabled="True" CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}" CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}" DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}" DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}" FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}" FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}" PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" PointerOverBackground="{ThemeResource SystemControlHighlightListLowBrush}" PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}" SelectedBackground=”White” SelectedForeground=”{ThemeResource SystemControlHighlightAltBaseHighBrush}” SelectedPointerOverBackground=”{ThemeResource SystemControlHighlightListAccentMediumBrush}” PressedBackground=”{ThemeResource SystemControlHighlightListMediumBrush}” SelectedPressedBackground=”{ThemeResource SystemControlHighlightListAccentHighBrush}” DisabledOpacity=”{ThemeResource ListViewItemDisabledThemeOpacity}” DragOpacity=”{ThemeResource ListViewItemDragThemeOpacity}” ReorderHintOffset=”{ThemeResource ListViewItemReorderHintThemeOffset}” HorizontalContentAlignment=”{TemplateBinding HorizontalContentAlignment}” VerticalContentAlignment=”{TemplateBinding VerticalContentAlignment}” ContentMargin=”{TemplateBinding Padding}” CheckMode=”Inline”/> 但这不适合我。 SelectedBackground-Border仍为蓝色。 但为什么? 我的错误在哪里?

winRT拖放,交换两个项目而不是插入

我是WPF的长期用户,但对WinRT来说是新手。 我想知道是否有内置方式或简单的方法来集成容器中的交换function,以便交换交换容器中的两个项目。 所需的行为是拖动一个项目并将其放在另一个项目上,并将拖动的项目和拖动它的项目放在容器交换的位置。 示例我有一个列表1 2 3 4 5 6 7 8,如果我拖动7 “on” 4我希望交换两个项目,以便结果列表变为1 2 3 7 5 6 4 8 我目前正在使用带有ItemsWrapGrid的GridView作为它的容器来显示大量的图片缩略图。 我需要能够重新排序它们,最常用的操作是交换两个图像的位置。 或者,如果没有内置方式,你能不能告诉我从头开始做的“正确”方向是WinRT? 我正在考虑不在容器处理拖放而是在项目级别,并手动交换ObservableCollection的项目?