本文介绍了Windows 8.1中如何解决这个过时的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我已经升级我的项目从Windows 8.0是Windows 8.1,得到了过时的代码一些警告。他们有的我都固定的,其中一些并非如此。 下面是我无法修复,但没有找到任何信息的最后警告的图像。 所有的警告指的是同样的方法,它说,它已经过时了,我应该怎么做才能让没有过时代码? 下面是代码: 警告2号 ///<总结> ///转换<见CREF =ApplicationViewState/>值转化为可视状态 ///在页面中管理字符串。默认实现使用枚举值的名称。 ///子类可以重写此方法来控制使用的映射方案。 ///< /总结> ///< PARAM NAME =ViewState的>对其中一个视觉状态需要查看状态和LT; /参数> ///<退货和GT;用于驱动视觉州名///<见CREF =VisualStateManager/>< /回报> ///< seealso CREF =InvalidateVisualState/> 受保护的虚拟串DetermineVisualState(ApplicationViewState ViewState中) {返回viewState.ToString(); } 警告号码1。 //设置控制 VisualStateManager.GoToState的初始可视状态(控制,DetermineVisualState(ApplicationView.Value),FALSE); 警告3号。 字符串的visualSTATE = DetermineVisualState(ApplicationView.Value); 以上所有的代码,则调用DetermineVisualState它被废弃的方法,它提供要查询的直接窗口布局的大小,但它是什么意思 的注:的它是LayoutAwarePage,所以在这里我没有写任何代码,这是由于Windows 8.0的实现。 任何帮助,将不胜感激,并预先感谢! 解决方案 从MSDN:的如何停止使用LayoutAwarePage 在Windows 8中,微软的Visual Studio模板生成 LayoutAwarePage类管理基于 ApplicationViewState的视觉状态。在Windows 8.1,ApplicationViewState是弃用,LayoutAwarePage不再包含在Windows应用商店的应用程序可视 Studio模板。继续使用 LayoutAwarePage可以打破你的应用程序。为了解决这个问题,重写以适应新的最低视图状态,并创建一个基于窗口的大小事件。如果更新您的应用程序不同的大小,则必须处理Window.Current和Window.SizeChanged事件添加到您的应用程序的 UI适应新的大小。我们建议您停止使用 LayoutAwarePage,并直接从Page类继承的类。 以下是如何停止使用LayoutAwarePage: 保护覆盖无效的OnNavigatedTo(NavigationEventArgs E) { base.OnNavigatedTo(E); this.Loaded + = PageLoaded; this.Unloaded + = PageUnloaded; } 私人无效PageUnloaded(对象发件人,RoutedEventArgs E) { Window.Current.SizeChanged - = Window_SizeChanged; } 私人无效PageLoaded(对象发件人,RoutedEventArgs E) { Window.Current.SizeChanged + = Window_SizeChanged; } 私人无效Window_SizeChanged(对象发件人,Windows.UI.Core.WindowSizeChangedEventArgs E) {如果(e.Size.Width< = 500) { //VisualStateManager.GoToState(this,state.State,转换); } ,否则如果(e.Size.Height> e.Size.Width) { //VisualStateManager.GoToState(this,state.State,转换); } ,否则 { //VisualStateManager.GoToState(this,state.State,转换); } } 的Search~~V为重新定位到Windows 8.1预览在这个链接 打开LayoutAwarePage并更改DetermineVisualState方法没有再依靠ApplicationViewState,而是依赖于中的窗口的大小。例如,您可以返回VerticalLayout的时候你的应用程序窗口宽度小于500像素和HorizontalLayout当,它比500像素更大。因为这种方法是虚拟的,它被设计成在需要时可以在每一页覆盖(因为它是在 SplitPage完成)。如果你的布局和可视状态不同,您可以在任何网页上的覆盖。只要确保在每个页面以匹配这些新的字符串的重命名可视状态。 I have upgraded my project to windows 8.1 from windows 8.0 and got some warnings of obsolete codes. Some of them I have fixed, and some of them not.Here is an image of the last warnings that I couldn't fix and couldn't find any information.All warnings refers to the same method, and it says that it is obsolete, what should I do to get the not obsolete code?Here are the codes:warning number 2./// <summary>/// Translates <see cref="ApplicationViewState" /> values into strings for visual state/// management within the page. The default implementation uses the names of enum values./// Subclasses may override this method to control the mapping scheme used./// </summary>/// <param name="viewState">View state for which a visual state is desired.</param>/// <returns>Visual state name used to drive the/// <see cref="VisualStateManager" /></returns>/// <seealso cref="InvalidateVisualState" />protected virtual string DetermineVisualState(ApplicationViewState viewState){ return viewState.ToString();}Warning number 1.// Set the initial visual state of the controlVisualStateManager.GoToState(control, DetermineVisualState(ApplicationView.Value), false);Warning number 3.string visualState = DetermineVisualState(ApplicationView.Value);All the above codes, calls to the DetermineVisualState method which is deprecated, it offers to query for window layout sizes directly, but what does it mean?Note: It is the LayoutAwarePage, so I haven't wrote here any code, this is Windows 8.0 implementation.Any help would be appreciated and thanks in advance ! 解决方案 From MSDN: How to stop using the LayoutAwarePage In Windows 8, Microsoft Visual Studio templates generate the LayoutAwarePage class to manage the visual states based on the ApplicationViewState. In Windows 8.1, ApplicationViewState is deprecated and LayoutAwarePage is no longer included in the Visual Studio templates for Windows Store apps. Continuing to use the LayoutAwarePage can break your app. To fix this, rewrite your view to accommodate the new minimum view state, and create events based on the window size. If you update your app to different sizes, you must handle the Window.Current and Window.SizeChanged events to adapt the UI of your app to the new size. We recommend that you stop using the LayoutAwarePage, and inherit the classes directly from the Page class. Here's how to stop using the LayoutAwarePage:protected override void OnNavigatedTo(NavigationEventArgs e){ base.OnNavigatedTo(e); this.Loaded += PageLoaded; this.Unloaded += PageUnloaded; } private void PageUnloaded(object sender, RoutedEventArgs e) { Window.Current.SizeChanged -= Window_SizeChanged; } private void PageLoaded(object sender, RoutedEventArgs e) { Window.Current.SizeChanged += Window_SizeChanged; } private void Window_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e) { if (e.Size.Width <= 500) { //VisualStateManager.GoToState(this, state.State, transitions); } else if (e.Size.Height > e.Size.Width) { //VisualStateManager.GoToState(this, state.State, transitions); } else { //VisualStateManager.GoToState(this, state.State, transitions); } }Search for Retargeting to Windows 8.1 Preview in this link Open LayoutAwarePage and change the DetermineVisualState method to no longer rely on the ApplicationViewState and instead be dependent on the window size. For instance, you could return VerticalLayout when your app window width is less than 500px and HorizontalLayout when it’s greater than 500px. As this method is virtual, it is designed to be overridden in each page when needed (as it’s done on the SplitPage). You can override this on any page if your layouts and visual states differ. Just make sure to rename the visual states on each of your pages to match these new strings. 这篇关于Windows 8.1中如何解决这个过时的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-18 08:24