0

I have looked and looked, but nothing works.

Say I have something like this:

namespace A{

    partial class B : Window {
        //some definitions
    }

    class E {
        public enum en {a, b, c}
    }
}

and then in the XAML:

<Window x:Class="A.B"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:A">
<Window.Resources>
        <ObjectDataProvider MethodName="GetValues"
                        ObjectType="{x:Type sys:Enum}"
                        x:Key="vals">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="en" />           <<<this line
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </Window.Resources>
..rest of XAML ...
</window>

Now the marked line gives me the error:

Type 'en' was not found.

it is the same if I change it to

local:en
E+en
local:E+en

How do I solve this problem? Thanks very much

3
  • Can't you declare the enum outside of the E class ? I'm sure that local:en would work then. And shouldn't the xmlns look like: xmlns:local="clr-namespace:A;assembly=<assemblyName>" Commented Jun 23, 2011 at 16:04
  • @hyp the enum is encapsulated in another external class, I really can't declare it outside of the E class Commented Jun 23, 2011 at 22:05
  • @Lars sorry, wrong error message, edited now Commented Jun 23, 2011 at 22:06

1 Answer 1

1

just try this

<Window x:Class="WpfApplication12.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication12"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Window.Resources>
    <ObjectDataProvider x:Key="dataFromEnum"
                        MethodName="GetValues"
                        ObjectType="{x:Type System:Enum}">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="local:Window1+en" />
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</Window.Resources>
<Grid>
    <ListView ItemsSource="{Binding Source={StaticResource dataFromEnum}}"
              Margin="10,10,10,0"
              Height="80"
              VerticalAlignment="Top" />
    <ComboBox ItemsSource="{Binding Source={StaticResource dataFromEnum}}"
              Margin="10,0,10,80"
              Height="25"
              VerticalAlignment="Bottom" />
    <ListBox ItemsSource="{Binding Source={StaticResource dataFromEnum}}"
              Margin="10,0,10,12"
              Height="93"
              VerticalAlignment="Bottom" />
</Grid>

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
    }
    public enum en { a, b, c }

}
Sign up to request clarification or add additional context in comments.

1 Comment

So I can't use an enum nested in an external class??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.