windows-8 – 在Windows应用商店应用程序后面的代码中转到Grid内
发布时间:2020-12-13 23:19:02 所属栏目:Windows 来源:网络整理
导读:所以我的xaml代码看起来像这样 – Grid x:Name="LayoutRoot" VisualStateManager.VisualStateGroups VisualStateGroup x:Name="CommonStates" 我无法使用GoToVisualState行为,因为我需要在运行此动画之前进行一些检查.所以我想我必须在后面的代码中调用类似G
所以我的xaml代码看起来像这样 –
<Grid x:Name="LayoutRoot"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> 我无法使用GoToVisualState行为,因为我需要在运行此动画之前进行一些检查.所以我想我必须在后面的代码中调用类似GoToState或GoToElementState的东西. 但是,WinRT中似乎不存在ExtendedVisualStateManager.我试过用 VisualStateManager.GetCustomVisualStateManager(this.LayoutRoot) 但它总是返回null. 这有什么解决方法吗?
刚想通了.
首先创建一个帮助程序类,就像我们以前在Silverlight或Windows Phone中使用它一样(我从here获取了这段代码并对其进行了一些修改,因此当一个元素没有附加任何可视状态组时,它会自动进行搜索其父级,直到找到任何). public class ExtendedVisualStateManager : VisualStateManager { protected override bool GoToStateCore(Control control,FrameworkElement stateGroupsRoot,string stateName,VisualStateGroup group,VisualState state,bool useTransitions) { if ((group == null) || (state == null)) { return false; } if (control == null) { control = new ContentControl(); } return base.GoToStateCore(control,stateGroupsRoot,stateName,group,state,useTransitions); } public static bool GoToElementState(FrameworkElement element,bool useTransitions) { var root = FindNearestStatefulFrameworkElement(element); var customVisualStateManager = VisualStateManager.GetCustomVisualStateManager(root) as ExtendedVisualStateManager; return ((customVisualStateManager != null) && customVisualStateManager.GoToStateInternal(root,useTransitions)); } private static FrameworkElement FindNearestStatefulFrameworkElement(FrameworkElement element) { while (element != null && VisualStateManager.GetCustomVisualStateManager(element) == null) { element = element.Parent as FrameworkElement; } return element; } private bool GoToStateInternal(FrameworkElement stateGroupsRoot,bool useTransitions) { VisualStateGroup group; VisualState state; return (TryGetState(stateGroupsRoot,out group,out state) && this.GoToStateCore(null,useTransitions)); } private static bool TryGetState(FrameworkElement element,out VisualStateGroup group,out VisualState state) { group = null; state = null; foreach (VisualStateGroup group2 in VisualStateManager.GetVisualStateGroups(element)) { foreach (VisualState state2 in group2.States) { if (state2.Name == stateName) { group = group2; state = state2; return true; } } } return false; } } 然后你需要手动将xaml更新为这样的东西 – <VisualStateManager.CustomVisualStateManager> <common:ExtendedVisualStateManager /> </VisualStateManager.CustomVisualStateManager> <VisualStateManager.VisualStateGroups> <VisualStateGroup .../> </VisualStateManager.VisualStateGroups> 我想这个解决方案的优点是你仍然可以在Blend的States选项卡中看到视觉状态,对于Blend爱好者来说这很酷. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Windows防火墙 – Windows Server 2008防火墙:远程IP地址的
- windows-server-2008 – MSIZAP仍然有用,还是已经过时了?
- 如何在Windows控制台中递归使用“svn add”?
- 6.Tray Monitor服务(端监控服务)
- NT安全设置
- active-directory – 如何验证Windows Server 2008R2 Activ
- batch-file – 如何使用通配符文件名作为命令行参数调用Win
- windows-server-2003 – Windows Server 2003中的$hf_mig $
- Windows10 下安装 Apache2.4+PHP7.1+MySQL5.7
- Windows 7多监视器RDC问题