gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:16:00 25 4
gpt4 key购买 nike

我在 VS2010 中有一个使用 XAML 的项目,现在我需要将其加载到 Expression Blend 4 中。该项目在 VS2010 中构建并运行,这是它第一次加载到 Blend 中。即使成员未被识别,它也会在 Blend 中构建和运行。

为什么 Scale 属性无法识别以及为什么它在正常工作时显示为错误?

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

在许多包含对用户控件的引用的 .xaml 文件中,有一个属性无法被 Blend 识别,并出现错误:

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

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

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

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

在下面的代码中,即使 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>

这是 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();
}
}
}

在我的 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>

最佳答案

这是解决方案。在应用程序的 .csproj 文件中,更改以下内容:

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

对此:

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

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

关于wpf - 将 VS2010 项目加载到 Expression Blend 时出现属性无法识别或无法访问错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10146250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com