wpf - WPF 中不存在另一个名称的问题

标签 wpf c#-4.0 mvvm visual-studio-2012

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

  • VS2012 WPF 设计器不适用于此 XAML 文件。它显示消息设计 View 对于 x64 和 ARM 目标平台不可用。
  • 我收到以下消息命名空间“clr-namespace:VideoDatabase.Enums”中不存在名称“EnumConverter”。同样,这不会干扰编译或执行项目。

  • 这是 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 命名空间中的公共(public)类,位于当前程序集中。这是该类的代码片段:
    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类(class)在主大会
  • 如果我注释掉 <local:EnumConverter x:Key="enumConverter"/>设计师的作品。
  • 最佳答案

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

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

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

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

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

    关于wpf - WPF 中不存在另一个名称的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14415854/

    相关文章:

    WPF/XAML : multiple controls using the same events - is there an easier way?

    c#-4.0 - Windows Service中的错误处理

    c# - 将 Nullable<Boolean> 转换为通用类型

    c# - 访问 UserControl 中的主窗口控件

    wpf - 不要在 WPF 列表框中显示部分项目

    javascript - Knockout JS 从数组中调用错误的对象

    wpf - ObservableCollection 和 INotifyPropertyChanged 有什么区别?

    asp.net-mvc - 从 ASP.NET MVC2 Controller 返回临时 View 模型

    wpf - 如何使用 MVVM 创建定时弹出窗口?

    c#-4.0 - 如何告诉我的 C# 应用程序关闭它在 FileInfo 对象或可能的 Bitmap 对象中打开的文件?