4

在本项目中,代码编译执行正常;但是,我需要帮助解决两个问题:

  1. VS2012 WPF 设计器不适用于此 XAML 文件。它显示消息设计视图对于 x64 和 ARM 目标平台不可用

  2. 我收到以下消息The name "EnumConverter" doesn't exist in the namespace "clr-namespace:VideoDatabase.Enums"。同样,这不会干扰编译或执行项目。

这是 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>

EnumConverter是 VideoDatabase.Enums 命名空间中的公共类,位于当前程序集中。这是该类的代码片段:

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);
        }
    }
}

到目前为止,我已经检查了以下内容:

  • 确认目标框架是 .NET Framework 4.5
  • 确认EnumConverter课程在主程序集中
  • 如果我注释掉<local:EnumConverter x:Key="enumConverter"/>设计师的作品。
4

3 回答 3

4

您很可能已将构建目标平台设置为仅 x64 位。

然后发生的事情是您的输出程序集仅为 64 位,基于 x86 的 WPF 设计器无法加载。

转到项目属性->Build->Target Platform并将其设置为Any.

编辑:如果您有需要从 32 位 WPF 设计器访问的程序集/代码(在本例中为值转换器),那么您必须将它们与其他 64 位程序集分开。我很难找到为什么值转换器需要位于 64 位 DLL 中的任何原因,而不是像您的情况那样的硬依赖。

如果这对你来说是不可能的,我认为你将不得不忍受你不能在你的场景中使用设计器的事实。

于 2013-01-19T17:07:04.927 回答
1

我相信您的问题是,由于某种原因,WPF 程序集在构建时不喜欢查看其他程序集。它默认认为您引用的任何命名空间都在调用程序集中,因此您所说的行

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

被 WPF 引擎解释为

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

您有时可以通过将程序集的构建配置更改为不同的体系结构和东西来获得更进一步,但通常当您尝试加载包含尝试读取枚举的组件的页面时,它仍然会崩溃。您需要做的是指定您的枚举所在的程序集,如:

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

你应该准备好了吗?

于 2015-04-29T20:38:49.863 回答
0

是不是因为你缺少转换器的预编译器......就像......

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

}
于 2013-01-19T16:25:39.647 回答