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

    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?

    Wednesday, November 10, 2010 10:46 AM

All replies