Is there a way to debug the current visual state?
I'm finding that often times I have controls with multiple visual state groups, and it isn't always clear to me what the current visual state of each group is. Is there a way to debug this / get this? I was trying to look for something in the noesis inspector tool but I couldn't figure it out.
thanks!
sam
thanks!
sam
-
-
sfernandez
Site Admin
- Posts: 2710
- Joined:
Re: Is there a way to debug the current visual state?
There is no such information in the Inspector, but in code you can get the collection of visual state groups and ask for the current state:
In a Control visual states are defined in the template root, for UserControls they are defined in the Content, so you have to get the groups collection from the Content element.
We will study how to expose this information in the Inspector to improve debugging in those situations, I created a ticket for that: #2399
Code: Select all
void PrintCurrentStates(Control control)
{
FrameworkElement root = VisualTreeHelper.GetChild(control, 0) as FrameworkElement;
VisualStateGroupCollection groups = VisualStateManager.GetVisualStateGroups(root);
foreach (VisualStateGroup group in groups)
{
VisualState state = group.GetCurrentState(root);
Console.WriteLine($"Group: {group.Name}, CurrentState: {state.Name}");
}
}
We will study how to expose this information in the Inspector to improve debugging in those situations, I created a ticket for that: #2399
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 3 guests