UWP开发学习笔记3
获取可视化状态列表
private void Button_Click(object sender, RoutedEventArgs e) { //获取CheckBox控件可视化树中的子元素数量 int count = VisualTreeHelper.GetChildrenCount(ckbox); if (count > 0) { //获取CheckBox控件模板中的根元素 FrameworkElement rootElement = VisualTreeHelper.GetChild(ckbox, 0) as FrameworkElement; if (rootElement != null) { //获取状态组列表 var groups = VisualStateManager.GetVisualStateGroups(rootElement); foreach (VisualStateGroup group in groups) { Debug.WriteLine("状态组:" + group.Name); foreach (VisualState vs in group.States) { Debug.WriteLine("\t状态:" + vs.Name); } } } } }