0

I'm fairly new to MVVM and WPF and have recently started porting an application from WinForms. I'm trying to change a visual state from the ViewModel but can't figure it out.

I have tried all the previously posted solutions but nothing seems to be working. This is what I have:

<UserControl x:Class="WPFApp.View.AddItem"
...
    DataContext="{Binding}" helper:StateManager.VisualStateProperty="{Binding Path=VisualStateName}">
<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="OverlayStates">
        <VisualStateGroup.Transitions>
...

And in the ViewModel:

    private string visualStateName;
    public string VisualStateName
    {
        get
        {
            return visualStateName;
        }
        set
        {
            visualStateName = value;
            OnPropertyChanged("VisualStateName");
        }
    }

When ever I output the value of VisualStateName it is null and if I set it it doesn't change the state of the View. I can't figure out what I'm doing wrong, I've found some notes on other people mistakes but don't seem to have made any of those. Can anyone see what I've done wrong?

I am using the StateManager found here: http://tdanemar.wordpress.com/2009/11/15/using-the-visualstatemanager-with-the-model-view-viewmodel-pattern-in-wpf-or-silverlight/

Itzalive
  • 370
  • 4
  • 14
  • Are you sure your DataContext binding is correct – sa_ddam213 Aug 15 '14 at 03:53
  • `VisualState` belongs in the UI, not the view model. – Sheridan Aug 15 '14 at 07:50
  • Other elements are correctly bound to the DataContext. I managed to get it working using the interactivity library but not using this StateManager. In the end I decided that the VisualState shouldn't be in the ViewModel as you suggest and just handled some events in the code behind. Thanks – Itzalive Aug 15 '14 at 17:41

0 Answers0