locked
Is it a bug in Visual Studio 2008 in WPF Designer when binding to enum defined inside of class? RRS feed

  • Question

  • Hello,

     

    I have following problem:

    when defining an enumeration inside of class (either static class or not) I can bind to this enum, however the WPF Designer inside Visual Studio does not display designed GUI anymore and show an error Type "MyClass+MyEnum" was not found.

    However I can compile and execute the code and in the combobox all enum- values are listed.

     

    Code behind:

      public class MyClass
      {
        public enum MyEnum { enumValue01, enumValue02, enumValue03, enumValue04, enumValue05 }
      }

     

    My xaml-code:

    <Window x:Class="SampleBindingOfNestedEnumToComboBox.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:sys="clr-namespace:System;assembly=mscorlib"     
      xmlns:local="clr-namespace:SampleBindingOfNestedEnumToComboBox"
      Title="Window1" Height="300" Width="300">
    
      <Window.Resources>
        <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="odp">
          <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="local:MyClass+MyEnum"/>
          </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
      </Window.Resources>
      <Grid>
        <ComboBox ItemsSource="{Binding Source={StaticResource odp}}"/>
      </Grid>
    </Window>

    As I mentioned I can compile and execude thos code, however in VS Designer I just see warning message  "Problem Loading the document contains errors that must be fixed  before the designer can be loaded..."

    When I click on Reload the designer I get following message:

    Error    1    Type 'MyClass+MyEnum' was not found.   

    Do I something wrong or is there some problem with VS designer?

    • Moved by Victor_Chen Thursday, November 11, 2010 2:30 AM WPF designer (From:Visual Studio Editor)
    • Edited by Evgeni ABC Thursday, November 11, 2010 8:38 AM
    • Moved by Jie Bao Monday, November 22, 2010 4:39 AM WPF designer (From:Windows Presentation Foundation (WPF))
    Tuesday, November 9, 2010 10:53 AM

All replies

  • Hi Evgeni,

     

    Thanks for your post.

    I think this is a WPF designer issue and I'm going to move it.

    I'm sure you can get more useful information there.

     

    Best Regards,

    Ziwei Chen

     

     

    Thursday, November 11, 2010 2:28 AM
  • Hi Evgeni,

    I think it is not a bug, the cause of your issue is "<x:Type TypeName="local:MyClass+MyEnum"/>", because I can find some technic articles on using "+" to visit inner class, however, I can not find any technic documents about you can use "+" in Xaml to visit inner class that is a Enum. So I think you can not use "+" to visit inner class directly in your designer.

    Now I think you can try to do actions as follow to workaround it.

    1) You try to can remove your Window.Resources in Windows.xaml to your Application.Resources in App.xaml, then your designer can display normally.

    2) You can try to  remove your MyEnum out of the class.

    Hope it can help you.

    Best regards,

    Sheldon _Xiao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    Thursday, November 11, 2010 3:31 AM
  • I have noticed the same behavior and discussed here:
    http://shujaatsiddiqi.blogspot.com/2010/08/wpf-loading-combo-box-items-with-enum.html

    This is a know issue on Connect too:
    https://connect.microsoft.com/VisualStudio/feedback/details/361509/xaml-designer-cannot-handle-typename-with-nested-classes?wa=wsignin1.0

    Thanks,
    Muhammad


    Muhammad Siddiqi
    • Proposed as answer by Victor_Chen Thursday, November 11, 2010 4:54 AM
    Thursday, November 11, 2010 4:44 AM
  • Hi Evgeni,

    I think it is not a bug, the cause of your issue is "< x : Type TypeName ="local:MyClass+MyEnum"/> ", because I can find some technic articles on using "+" to visit inner class, however, I can not find any technic documents about you can use "+" in Xaml to visit inner class that is a Enum. So I think you can not use "+" to visit inner class directly in your designer.

    Now I think you can try to do actions as follow to workaround it.

    1) You try to can remove your Window.Resources  in Windows.xaml to your Application.Resources in App.xaml, then your designer can display normally.

    2) You can try to  remove your MyEnum  out of the class.

    Hope it can help you.

    Best regards,

    Sheldon _Xiao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!


    Hello Sheldon,

     

    unfortunally both suggestions you made are not applicable for me:

    - nested enumeration comes from (external) code I can not change

    - UserControl where problem occures is located in class library, so no App.xaml is available. And I do not want to create some strange constructs in order to workaround some stuff, that in my opinion is basic stuff have had been tested before releasing VS.

    I found it really strange that this issue (over 2 year old, see microsoft connect link provided by Muhammad) still not fixed.

    Thursday, November 11, 2010 8:37 AM
  • Hi Evgeni,

    Thank you for your feedback.

    I have understood what your concern is, you do not want to workaround this issue, you want to fix it, I think it is too hard.

     -->  I found it really strange that this issue (over 2 year old) still not fixed.

    I think this question I can explain to you, now The "Microsoft Visual Studio 2010/2008" remains "XAML Compiler" which producted in 2006, so

    I think this issue has not been fixed can be understood. and as far as I know, a "XAML Compiler" producted in 2009 has been tested. I think

    we can wait.

    Thanks for discussing, have a nice day.

    Sheldon _Xiao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    Thursday, November 11, 2010 9:04 AM
  • Hi Evgeni,

    Sorry for the late reply. Due to some problems in our system, we failed to identify you as an MSDN subscriber. I tested it in Visual Studio 2010, unfortunately, this issue still exists. In our MSDN forums, there is a Visual Studio WPF Designer form which is for the WPF Designer ("Cider") in Visual Studio. You could ask it there, you may get a clear answer. Meanwhile, you could vote the issue on the connect site. Thanks.

    Sincerely,
    Bob Bao

    MSDN Subscriber Support in Forum 

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download all in one code framework !
    Friday, November 12, 2010 9:51 AM