13

How do I programmatically get the current Visual State of a WPF FrameworkElement? And by state I mean the states like "Normal", "MouseOver", "Disabled", etc.

EDIT: Basically, I am changing the Visual state of a button with VisualStateManager.GoToState(e, "MouseOver", true);, and I want to know what state to change it back to after I am done.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Kyle
  • 21,377
  • 37
  • 113
  • 200

3 Answers3

2

I think you have to know/remember the button state by yourself. VSM just displays the state in which the button is by GoToState method.

Edit: I've just found an article how to create a custom VSM that remembers control states.

Lukas Cenovsky
  • 5,476
  • 2
  • 31
  • 39
0

I think you should use GoToElementState method instead of GoToState method.

VisualStateManager.GoToElementState(LayoutRoot, "Add", true);
CoolBeans
  • 20,654
  • 10
  • 86
  • 101
Haritha
  • 1,498
  • 1
  • 13
  • 35
  • Strange, I don't even see this method. Of course I'm using the VisualStateManager from the WPF toolkit for .NET 3.5 so it may be different from the one built in in .NET 4.0 or the Silverlight one. – jpierson Feb 18 '13 at 02:47
0

I feel you've missed the point of WPF here, it's the View not the Model. You should not be storing state in the View. Store state in your Model(s) and use the View to represent it. On that basis you don't need to read the state of the View, you already know it.

I know this may seem like a lot of work at the moment but it'll pay you back in spades later.

Lazarus
  • 41,906
  • 4
  • 43
  • 54