Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property not recognized or not accessible error when loading VS2010 project into Expression Blend

I have a project in VS2010 that uses XAML and now I need to load it into Expression Blend 4. The project builds and runs in VS2010 and this is the first time it has been loaded into Blend. It DOES build and run in Blend even though the members are not recognized.

Why is the Scale property not recognized and why does it show up as an error when it functionally works?

EDIT Although this builds and runs, the XAML is not displayed graphically in Blend and so cannot be modified by a non-technical user.

In a number of the .xaml files that contain references to usercontrols there is an attribute that is not recognized by Blend with the error:

The member "XXXX" is not recognized or is not accessible

The property exists in the .cs code behind file and in each case the error message is the same.

I've looked at a lot of possible answers to this on the internet but none of them is a solution. The referenced items are not read-only. The various classes and properties are Public. I've also added the following WPF reference into the .csproj file, which was missing.

<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

In the following code, the Scale attribute is not recognized even though it exists as a property in the user control.

Here is the UserControl in MyLogo.xaml:

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

Here is the code behind in 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();
    }
}
}

In my Navigation.xaml file I have this:

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

like image 455
Brian Leeming Avatar asked Apr 13 '12 18:04

Brian Leeming


1 Answers

Here's the solution. In the application's .csproj file, change this:

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

to this:

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

Do not be fooled by the fact that Visual Studio reports that you are running in AnyCPU more in the configuration manager. You must hand-edit the .csproj file.

like image 66
Brian Leeming Avatar answered Oct 04 '22 13:10

Brian Leeming