6

我在 VS 2010 中创建我的 WPF 项目。在完成功能 GUI 的工作后,我想在 Blend 4 中编辑我的控件模板。但是当我在 Blend 中打开项目时,在 DesignMode 中,他告诉我


无效的 XAML


在结果窗口中,他写道:


Windows Presentation Foundation (WPF) 项目不支持 [ControlName]


其中 [ControlName] 是我在项目中使用的默认控件列表(例如 Window、DockPanel 等)

如何避免此问题并能够在 Expression-Blend4 的 DesignMode 编辑 WPF 表单?

编辑:

可能的解决方法。

Blend在比较了由和创建的空项目(* .csproj 文件)之后Studio,我发现VisualStudio用下一行创建它:

<PropertyGroup>
  <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
 ...

而 Blend 使用以下几行:

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

因此,如果您更改x86AnyCPU,Blend 将按预期打开项目。

4

2 回答 2

11

我以前只看到过一次此错误消息。在将新的解决方案文件与不会加载的解决方案文件进行比较后,我发现 Blend需要定义AnyCPU平台/配置。

如果这不起作用,请确保为 WPF 项目引用了所有必需的程序集:PresentationCorePresentationFrameworkWindowsBase.

高温下,

于 2011-08-18T22:19:16.730 回答
1

在浪费了一天的时间后,我发现了这个:

在文本编辑器中打开 .proj 文件并查看文件的最顶部,在 XML 中会有一个 PropertyGroup 部分的列表。看看第一个,如果它说的是 x86 或 AnyCPU 以外的任何东西,请将其更改为 AnyCPU 并保存。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>

应该:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

为什么?我不是 100% 确定,但似乎 Visual Studio 不会修改项目文件的这一部分(如果是,我不知道确切的时间),因为您在 UI 中选择构建配置并且它使用相反。但是,由于 Expression Blend(使用版本 4)不允许您选择构建配置,它只会选择最上面的配置。结果是您得到“无效的 XAML”,并且您的所有引用旁边都有刘海 (!)。

在我看来(并且知道我的分析可能有缺陷)这是 Expression Blend 的一个缺陷。它不仅应该能够使用工作室可以使用的任何构建配置,您还应该能够选择它。

于 2012-04-26T15:28:56.093 回答