Question based on StackOverflow (answered) or you could see StateHelper itself (updated) on GitHub
It works! But I don't understand which way that helper resolve dependency view model from view, when helper method SetState get DependencyObject (control from view) as input parameter. It meens that anyway view model has to have a link to control (it's awful) and pass it to helper.
I try to ask another way (just for case if you hard to understand my english). How can I dinamically change visual state of control from view model. And obvious if you can give me an example as simple as it can be.
Also i haven't ways as triggers. I have to change visual state based on change view model property. And triggers in WinRT don't work the way i used to see.
Maybe i think in wrong way and this code bind state to property name that hides in StateHelper. But I still can't do it and I can't understand how it has to be for a panel (user control) with 100 items where view model (of this panel) has to change state of every item.
it was a stupid question and I'll answer for all those who also need some sleep before ask something like that.
A divil hides in this snippet of using StateHelper
<controls:SomeControl x:Name="ball" MyApp:StateHelper.State="{Binding State, Mode=TwoWay}"/>
"State" is a property from your view model and it's just a string with a name of a state. All you need is change it and with help of "two way" binding it call StateHelper.SetState for right conrol (In my case I used a wrapper for contorl - "ControlName"WithStates and I can set a property of contol state in panel view model for choosen control)
it was a stupid question and I'll answer for all those who also need some sleep before ask something like that.
A divil hides in this snippet of using StateHelper
<controls:SomeControl x:Name="ball" MyApp:StateHelper.State="{Binding State, Mode=TwoWay}"/>
"State" is a property from your view model and it's just a string with a name of a state. All you need is change it and with help of "two way" binding it call StateHelper.SetState for right conrol (In my case I used a wrapper for contorl - "ControlName"WithStates and I can set a property of contol state in panel view model for choosen control)
Also I use enum type in view model and converter in view. Thanks to this I'm no longer use strings in my view model and my view snippets looks like
<local:Ball DataContext="{Binding}" common:StateHelper.State="{Binding State, Mode=TwoWay, Converter={StaticResource EnumToBallStatesConverter}}"/>