4

In this project, the code compiles and executes properly; however, there are two issues I need help resolving:

  1. The VS2012 WPF designer does not work on this XAML file. It displays the message Design view is unavailable for x64 and ARM target platforms.

  2. I receive the following message The name "EnumConverter" does not exist in the namespace "clr-namespace:VideoDatabase.Enums". Again, this does not interfere with compiling or executing the project.

Here is the XAML:

<Window x:Class="VideoDatabase.Views.SortingView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:VideoDatabase.Enums"
        Title="Sort and Filter" SizeToContent="WidthAndHeight" ResizeMode="NoResize"
        Background="LightGray">
    <Window.InputBindings>
        <KeyBinding Gesture="Escape" Command="{Binding CloseWindowCommand}"/>
    </Window.InputBindings>
    <Window.Resources>
        <!-- Next line generates Intellisene error; however, the code compiles and executes -->
        <local:EnumConverter x:Key="enumConverter"/>
    </Window.Resources>

The EnumConverter is a public class in the VideoDatabase.Enums name space and is located in the current assembly. Here is a code snippet of the class:

namespace VideoDatabase.Enums
{
    public class EnumConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string parameterString = parameter as string;
            if (parameterString == null)
                 return DependencyProperty.UnsetValue;

            if (Enum.IsDefined(value.GetType(), value) == false)
                return DependencyProperty.UnsetValue;

            object parameterValue = Enum.Parse(value.GetType(), parameterString);

            return parameterValue.Equals(value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string parameterString = parameter as string;
            if (parameterString == null)
                return DependencyProperty.UnsetValue;

            return Enum.Parse(targetType, parameterString);
        }
    }
}

So far, I have checked the following:

  • Confirmed the target framework is .NET Framework 4.5
  • Confirmed the EnumConverter class is in the main assembly
  • If I comment out <local:EnumConverter x:Key="enumConverter"/> the designer works.
James
  • 954
  • 2
  • 13
  • 27

3 Answers3

4

Most likely have you set your build target platform to x64 bit only.

What happens then is that your output assembly is 64bit only, which the x86 based WPF designer can't load.

Go to the project properties->Build->Target Platform and set that to Any.

EDIT: If you have assemblies/code (in this case value converters) that needs to be accessed from the 32bit WPF designer, then you will have to separate them out from your otherwise 64bit assemblies. I would be hard pressed to find any reason why value converters need to be in a 64bit DLL other than a hard dependency as in your case.

If that's not possible for you, I think you will have to live with the fact that you can't use the designer in your scenario.

Magnus Johansson
  • 28,010
  • 19
  • 106
  • 164
  • Good suggestion but I have another project in the solution that produces a 64-bit DLL. The other thing is why does the designer work when I comment out the `local` line even though it's a 64-bit project. – James Jan 19 '13 at 19:34
  • Well, the WPF designer has no reason to load your 64bit assembly then. – Magnus Johansson Jan 19 '13 at 22:07
  • Just out of curiosity, why do you have to force your platform target into 64bit? – Magnus Johansson Jan 19 '13 at 22:20
  • In my solution, I have two projects: one C# and the other is managed C++ (CLI). The managed C++ project calls the 64-bit version of Turbo Libjpeg. To get everything to work together, I set all projects in the solution to 64-bit only. If there's a better way, I'm open to suggestions. – James Jan 19 '13 at 22:25
  • If there's a 32bit version available, use that while designing/debugging and set your main assembly to target Any. Create a new Configuration in VS, like "Release-x64", set target to x64 and put your dependent 64bit assembly in a .\AMD64 folder. I'd think (without knowing all details) that the 64bit is only needed when processing large amount of data in production? I had a similar scenario: http://stackoverflow.com/questions/145803/targeting-both-32bit-and-64bit-with-visual-studio-in-same-solution-project – Magnus Johansson Jan 19 '13 at 22:36
1

I believe your problem is that for some reason the WPF assembly doesn't like to look at other assemblies when it builds. It defaults to thinking that whatever namespace you are referencing is within the calling assembly, so the line where you've said

xmlns:local="clr-namespace:VideoDatabase.Enums"

is interpreted by the WPF engine as

xmlns:local="clr-namespace:VideoDatabase.Enums;assembly=thisAssembly"

You can sometimes get a little further by changing the build configurations of your assemblies to different architectures and stuff, but usually it will still crash when you try to load the page which contains the component that is trying to read your enum. What you need to do is specify the assembly your enum lives in as well, as:

xmlns:local="clr-namespace:VideoDatabase.Enums;assembly=enumAssembly"

and you should be good to go?

hcp
  • 486
  • 1
  • 3
  • 11
0

Is it because you are missing the precompiler of the converter... something like...

[ValueConversion(typeof(changing from type), typeof( changing TO type))]
public class BoolToVisibility : IValueConverter
{
   public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

}
DRapp
  • 47,638
  • 12
  • 72
  • 142