1

In order to bind a 'friendly' enum I follow this link

Databinding an enum property to a ComboBox in WPF

but I have this error:Unable to create 'Type' from the 'Status' string

this is my code behind

    public enum Status
    {
        [Description("Available.")]
        Available,
        [Description("Not here right now.")]
        Away,
        [Description("I don't have time right now.")]
        Busy
    }


    public Status CurrentStatus { get; set; }


    public MainWindow()
    {
        InitializeComponent();

    }

and this is my XAML

<Grid>
    <ComboBox 
        ItemsSource="{Binding Source={my:Enumeration {x:Type Status}}}" 
        DisplayMemberPath="Description" 
        SelectedValue="{Binding CurrentStatus}"  
        SelectedValuePath="Value"  />

</Grid>

what's I wrong?

thanks

Community
  • 1
  • 1
user1351709
  • 135
  • 1
  • 1
  • 4

1 Answers1

0

You are missing a namespace. If your code is in a namespace called MyProject then you need to add a reference to that at the top of your xaml file:

    <xmlns:proj="clr-namespace:MyProject" />

and then prefix your type accordingly:

    ItemsSource="{Binding Source={my:Enumeration {x:Type proj:Status}}}" 

EDIT: looking at your existing markup, using my:Status might be enough.

Dan Puzey
  • 33,626
  • 4
  • 73
  • 96
  • sorry I have:xmlns:my="clr-namespace:WpfApplication3" ..and ItemsSource="{Binding Source={my:Enumeration {x:Type my:Status}}}" but the error are the same – user1351709 Apr 23 '12 at 16:07
  • In which namespace is your type `Status` defined? – Dan Puzey Apr 23 '12 at 16:10
  • Well, is it called `Status` or `Status1`? – Dan Puzey Apr 23 '12 at 16:18
  • Ah, wait: have you nested your `enum` declaration *inside* your `MainWindow` class? If so, your class is actually called `my:MainWindow.Status`... – Dan Puzey Apr 23 '12 at 16:19
  • yes it is in MainWindow but with {x:Type my:MainWindow.Status} I have tha same error ...incredible but if I move in another class in the same assembly with this {x:Type my:Class1+Status} (reshaper help me suggesting '+' works !!! ...you are show me the way thanks – user1351709 Apr 23 '12 at 16:22