将VS2010项目加载到Expression Blend时,属性无法识别或无法访问错误

Bri*_*ing 8 wpf visual-studio-2010 visual-studio expression-blend expression-blend-4

我在VS2010项目使用XAML,现在我需要将其加载到Expression Blend的4项目建立和运行VS2010,这是它已经被加载到混合的第一次.即使成员未被识别,它也可以在Blend中构建和运行.

为什么Scale属性无法识别?为什么它在功能上有效时会显示为错误?

编辑虽然这构建和运行,但XAML不会在Blend中以图形方式显示,因此非技术用户无法修改.

在许多包含对usercontrols的引用的.xaml文件中,Blend无法识别出错误的属性:

The member "XXXX" is not recognized or is not accessible
Run Code Online (Sandbox Code Playgroud)

该属性存在于.cs代码隐藏文件中,并且在每种情况下错误消息都是相同的.

我在互联网上看了很多可能的答案,但没有一个是解决方案.引用的项目不是只读的.各种类和属性都是公共的.我还将以下WPF引用添加到.csproj文件中,该文件丢失了.

<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Run Code Online (Sandbox Code Playgroud)

在以下代码中,即使Scale属性作为用户控件中的属性存在,也无法识别它.

这是MyLogo.xaml中的UserControl:

<UserControl x:Class="NamespaceX.NamespaceY.UI.Shapes.MyLogo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="132" Width="105">
<Canvas>
    <Canvas.LayoutTransform>
        <ScaleTransform x:Name="st" CenterX="0" CenterY="0" />
    </Canvas.LayoutTransform>
    <Image Source="/Client;component/Images/MyLogo.png"/>
</Canvas>
Run Code Online (Sandbox Code Playgroud)

以下是MyLogo.xaml.cs中的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NamespaceX.NamespaceY.UI.Shapes
{
/// <summary>
/// Interaction logic for MyLogo.xaml
/// </summary>
public partial class MyLogo : UserControl
{
    public double Scale
    {
        get
        {
            return st.ScaleX;
        }
        set
        {
            st.ScaleX = value;
            st.ScaleY = value;
        }
    }

    public MyLogo()
    {
        InitializeComponent();
    }
}
}
Run Code Online (Sandbox Code Playgroud)

在我的Navigation.xaml文件中,我有这个:

<UserControl x:Class="NamespaceX.NamespaceY.UI.UserControls.Navigation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shape="clr-namespace:NamespaceX.NamespaceY.UI.Shapes"    
Height="185" Width="1280" Loaded="UserControl_Loaded">
<FrameworkElement.Resources>
    <ResourceDictionary Source="../Resources/Main.xaml" />
</FrameworkElement.Resources>
<Canvas>
    <shape:MyLogo Scale="1.2" Height="181.483" Canvas.Left="38" Canvas.Top="4" Width="188" />
    <StackPanel Canvas.Left="205" Canvas.Top="-2" Width="1062">

    </StackPanel>
</Canvas>
Run Code Online (Sandbox Code Playgroud)

Bri*_*ing 17

这是解决方案.在应用程序的.csproj文件中,更改此:

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
Run Code Online (Sandbox Code Playgroud)

对此:

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Run Code Online (Sandbox Code Playgroud)

不要被Visual Studio在配置管理器中报告您在AnyCPU中运行的事实所迷惑.您必须手动编辑.csproj文件.

  • 我同意一开始看起来很傻,但是当我拥有它时,我会确认它解决同样的问题.我一开始并没有意识到问题出现在没有改变的文件上我正在为x86,x64,AllCPU构建工作.但果然,Visual Studio将所有内容显示为AllCPU,但.cproj文件在几个地方显示x64.我关闭了解决方案,修复了cproj并重新打开/清理/构建,所有内容都恢复为属性可访问性.我所能说的只是"寻找侦探布莱恩·莱明" (4认同)

AMi*_*ico 10

它们与更改平台更改缓存的程序集有关.接受的答案是不可接受的.

这是我的建议:

  1. 关闭所有文件
  2. 清洁解决方案
  3. 重建解决方案

受影响的XAML现在应该没有构建错误.

这适用于我,您的结果可能会有所不同.