4
votes

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.
3

3 Answers

4
votes

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.

1
votes

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?

0
votes

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)

}