InvalidOperationException in VS2010 WPF Designer on Visual State Manager


  • Hi,

    When adding WPF styles through control templates and resourcedictionarys VS2010 throws an InvalidOperationException error in the designer on controls when certain properties are set, that link back to the Visual States. I thought this must be the way i was creating the Visual States (i am using Blend 4.0) but I am also getting the same error, even using the ControlTemplateExamples downloaded from the msdn site.  http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wpfsamples&DownloadId=7741

    I opened up the solution in VS2010, then opened MainWindow.xaml (split screen - designer and markup)


    'System.Windows.Media.Animation.ColorAnimation' animation object cannot be used to animate property 'Foreground' because it is of incompatible type 'System.Windows.Media.Brush'.

    ... there are 11 errors but the solution builds successfully and runs fine.

    If you look at the markup in MainWindow.xaml and the first set of buttons, the first error is linked to the "IsEnabled" property

    <Button Margin="8" IsEnabled="False" Content="Disabled" />

    Look at the corresponding template in Button.xaml and the VisualState "Disabled" ... if you remove the visual state then the error is removed from the MainWindow.xaml Markup. Looking at the rest of the errors they seem to be linked to visual states on Control Properties that if set on the markup (like IsEnabled, ReadOnly, etc) cause the designer to throw the Invalid Operation Exception.

    Hope you can help

    Cheers ... Rob. 

    03/ذو القعدة/1431 09:26 ص

جميع الردود

  • I got a similar problem with a style transfered from Blend 4 to VS 2010. The XAML works perfectly in Blend 4 and in Run mode in VS, but the designer cannot handle it.

    I have a trigger for IsEnabled declared, witch assigns a new GrdientBackground to the Panel.Background. As far as I know, these assignments (to 'Panel.Background') are the ones causing this problem.

    More specificly, the designer gives me this specific error:

    'System.Windows.Media.Animation.ColorAnimationUsingKeyFrames' animation object cannot be used to animate property 'BorderBrush' because it is of incompatible type 'System.Windows.Media.Brush'.

    I also get an error listed in the error list (very helpfull ;-):

    '[Unknown]' property does not point to a DependencyObject in path '(0).(1)[1].(2)'

    Is your problem related to an assignment to 'Panel.Background'? Or to an assignment of a gradient color? Or color of some kind?

    I am sorry I don't have an answer for you, but I taught mabee adding my experience to this thread would bump the thread and allow an expert to get more info on the issue (if it IS the same issue...)

    Thanks for your time!

    • تم التحرير بواسطة Jean-François Gay 02/ذو الحجة/1431 08:59 م Reformatting text.. You'd think Microsoft would have this figured out....
    02/ذو الحجة/1431 08:57 م
  • Hi,


    I have the same problem... And can't find a solution.

    Have you found a solution to the problem?


    kind regards,


    12/ذو الحجة/1431 05:01 م
  • Same problem here, anybody knows a solution?


    Thanks in advance,


    25/ذو الحجة/1431 09:58 م
  • The only way I found to get around it is to move the Storyboard out of the VisualState and into the ControlTemplate.Triggers for the given property.

    Like to know if there is a better way around - or if MS has a fix?



    • تم الاقتراح كإجابة بواسطة GDogedog 10/صفر/1432 03:50 م
    10/صفر/1432 03:46 م
  • I have same warning when I design my project. Then I search around and find a good solution from JOSSELUISS :

    " I saw that for background there was a Panel.Background. I erased Panel. since it should work on the textbox background and yes, the exception disappeared. I.e.


    <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"

    I replaced:

    <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"

    And wherever Panel was in.


    As you can see, the difference betwen them is : (Panel.Background) changed to (Background). <= This is the key.

    Now, you can use it to button, combobox, ... anything make the same error. 

    I want thank JOSSELUISS very much for this solution. And hope it will help everyone. Thanks.

    • تم الاقتراح كإجابة بواسطة Anh Nguyet Tran 23/صفر/1432 09:54 ص
    23/صفر/1432 09:53 ص