16
votes

There are very helpful tools out there to debug WPF applications in run-time like Snoop, WPF Inspector and Xaml Spy which allow you to sneak peek into running application and monitor property values, DataContext changes, routing events and even triggers switching.

But what I did not managed to find in any of them is the way how to monitor VisualStateManager (VSM) transitions between states on particular selected control in run-time.

Is there any tool that could help with figuring out why a control doesn't go into the particular expected state (considering absence of source code for this application/library)?

Update: The question is mostly about debugging compiled code, when you have no access to the source. For cases when you have access to source code here is pretty good explanation of one of the ways to go.

1
This is a good question. I think the only way is to make visual state manager as simple and thin as possible. Debugging UI stuff is a weak point of WPF. Therefore you might try to avoid it.Bill Zhang
@BillZhang - Yep, agree. And I certainly would like to avoid it if I could :/Sevenate
for example you can put state transitions into event handler in code behind. Since these code are purely UI related it does not hurt and break any design patterns.Bill Zhang
@BillZhang, that may work, but only if you are authoring the code that deal with VisualStateManager. But what shall we do if the there is some third-party UI component with custom control that leverage VSM and it just not work as expected but is essential to application?Sevenate

1 Answers

1
votes

There are some reasons why a control does not transect its states.

There might be more than one VisualStateGroup and its has been named as something.

Calling a visual state before a control is loaded.

VisualState will be applied only after the control's OnApplyTemplate call.

if there are any syntax error.

How ever the Visual states are not able to tract with something but it can be debugged with the return value of GoToState method.

Hope this would helpful..