我如何获得Button的VisualStates [英] How I can get VisualStates of a Button
问题描述
我想访问Button的VisualStates(默认WPF Button控件)。
I want to access VisualStates of a Button (Default WPF Button control).
我如何做到这一点,我使用下面的代码:
How I can do that, I used below code :
private void Button_Loaded(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
IList<VisualStateGroup> groups = (IList<VisualStateGroup>)VisualStateManager.GetVisualStateGroups(btn);
System.Diagnostics.Debug.WriteLine("group count for (Button) = " + groups.Count.ToString());
FrameworkElement fe = VisualTreeHelper.GetChild(btn, 0) as FrameworkElement;
groups = (IList<VisualStateGroup>)VisualStateManager.GetVisualStateGroups(fe);
System.Diagnostics.Debug.WriteLine("group count for " + fe.GetType().ToString() + " = " + groups.Count.ToString());
fe = VisualTreeHelper.GetChild(fe, 0) as FrameworkElement;
groups = (IList<VisualStateGroup>)VisualStateManager.GetVisualStateGroups(fe);
System.Diagnostics.Debug.WriteLine("group count for " + fe.GetType().ToString() + " = " + groups.Count.ToString());
fe = VisualTreeHelper.GetChild(fe, 0) as FrameworkElement;
groups = (IList<VisualStateGroup>)VisualStateManager.GetVisualStateGroups(fe);
System.Diagnostics.Debug.WriteLine("group count for " + fe.GetType().ToString() + " = " + groups.Count.ToString());
}
Anjum S Khan管理员/分析师Blog.TrackNifty.com
Anjum S Khan Admin/Analyst Blog.TrackNifty.com
推荐答案
嗨AnjumSKhan,
Hi AnjumSKhan,
请阅读粘贴帖子,特别是 引导
发布:主题行标签 已知问题适用于Windows 10 SDK和工具 。
Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools .
您是否开发了WPF应用程序?如果是这样,你应该能够在WPF中提出四个问题: https: //social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wpf 。
Do you develop a WPF app? If so, you should able to ask it in the WPF fourm: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wpf.
您是否开发了UWP应用程序?如果是这样,似乎我们没有在Button中设置我们无法通过 获取VisualStateGroup的VisualStateManager。 VisualStateManager.GetVisualStateGroups方法。
Do you develop an UWP app? If so, it seems if we do not set the VisualStateManager in the Button that we can not get the VisualStateGroup by VisualStateManager.GetVisualStateGroups method.
您希望获得什么?VisualStateGroup?我们似乎可以使用VisualTreeHelper来获取以Button样式命名为RootGrid的Grid。我们可以将Grid设置为VisualStateManager.GetVisualStateGroups方法以获取VisualStateGroup。
What do you want to get the VisualStateGroup? It seems we can use the VisualTreeHelper to get the Grid that named RootGrid in the style of the Button. And we can set the Grid to the VisualStateManager.GetVisualStateGroups method to get VisualStateGroup.
最好的问候,
Jayden Gu
Jayden Gu
这篇关于我如何获得Button的VisualStates的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!