Blend 3 在设计时找不到我的转换器/资源。(WPF)

发布于 2024-08-03 08:42:14 字数 1647 浏览 6 评论 0原文

我在将 Blend 与 Visual Studio 解决方案一起使用时遇到问题。

在运行时和编译时一切都很好。

正如您在图片中看到的,Blend 敦促我构建项目,但它并没有改变情况,即使在成功构建、重建、清理和构建之后也是如此。 build,还是一样,UI被设计师挡住了

有什么想法吗?

替代文本

编辑:拼写错误已修复,问题仍然存在。

转换器代码:

namespace BlendTest
{
    public class TestConvert : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ((bool)value) ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }  
}      



<Window
  x:Class="XP2Win7.UserInterface.ImageViewer.MainView.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:BlendTest"
  WindowState="Maximized"
  WindowStartupLocation="CenterScreen"
  Background="Transparent"
  Title="Test">
    <Window.Resources>
        <local:TestConvert x:Key="TestConvert"/>
    </Window.Resources>
    <Grid x:Name="RootLayout" >
        <TextBlock Text="Hello" Visibility="{Binding IsMargol, Converter={StaticResource TestConvert}}" FontSize="48" FontWeight="Bold" />
    </Grid>
</Window>

谢谢 爱丽儿

I'm having troubles using Blend with my visual studio solution.

In Runtime, and compile time everything is just fine.

As you can see in the picture, Blend urges me to Build the project, but it does not change the situation, even after a successful build, rebuild, clean & build, it is still the same, the UI is blocked from the designer

Any ideas?

alt text

EDIT: Typos fixed, problem persists.

Converter code:

namespace BlendTest
{
    public class TestConvert : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ((bool)value) ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }  
}      



<Window
  x:Class="XP2Win7.UserInterface.ImageViewer.MainView.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:BlendTest"
  WindowState="Maximized"
  WindowStartupLocation="CenterScreen"
  Background="Transparent"
  Title="Test">
    <Window.Resources>
        <local:TestConvert x:Key="TestConvert"/>
    </Window.Resources>
    <Grid x:Name="RootLayout" >
        <TextBlock Text="Hello" Visibility="{Binding IsMargol, Converter={StaticResource TestConvert}}" FontSize="48" FontWeight="Bold" />
    </Grid>
</Window>

Thanks
Ariel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

乖不如嘢 2024-08-10 08:42:14

看起来您的 XAML 中有拼写错误:

Alubm 而不是 AlbumBlentTest 而不是 BlendTest

我猜测这些错误实际上是真正的编译器错误,并且纠正上面的两个拼写错误很可能会“修复”设计者。


编辑:

我看到的最有可能的候选者是您的转换器位于与 XAML 文件不同的项目中(但位于同一解决方案中)。如果是这种情况,请确保在 XAML 声明中指定程序集,并确保正确引用其他项目(使用 BlendTest)。即:

xmlns:local="clr-namespace:BlendTest;assembly:BlendTest"

如果您引用在不同项目中定义的类型(带有命名空间),则程序集引用也需要存在。

It looks like you have typos in your XAML:

Alubm instead of Album and BlentTest instead of BlendTest

I'm guessing the errors are actually true compiler errors, and correcting the two typos above will most likely "fix" the designer.


Edit:

The most likely candidate that I see is that your converter is in a separate project from your XAML file (but in the same solution). If that's the case, make sure to specify the assembly in the XAML declaration, and make sure the other project (with BlendTest) is referenced correctly. ie:

xmlns:local="clr-namespace:BlendTest;assembly:BlendTest"

If your referring to a type (with namespace) defined in a different project, the assembly reference needs to exist, as well.

千寻… 2024-08-10 08:42:14

好吧,虽然我仍然不知道问题的原因。

解决方案如下:

  1. 我创建了一个新的代码库项目,并将所有控件和转换器移至此处。

  2. 我使用 XmlnsDefinition 属性来修饰程序集,以便每个程序集都对应于相同的命名空间。

  3. 修复所有引用。

瞧。

爱丽儿

Well, while the cause of the problem is still unknown to me.

The solution to the mess was as followed:

  1. I've created a new Code Library project, and moved there all my controls and converters.

  2. I used the XmlnsDefinition attribute to decorate the assembly so each was corresponding to the same namespace.

  3. fixing all the references.

and Voilà.

Ariel

你曾走过我的故事 2024-08-10 08:42:14

这个答案为我解决了这个问题:我将“平台目标”重置为“任何CPU”。

This answer fixed it for me: I reset the 'Platform Target' to 'Any CPU'.

您的好友蓝忘机已上羡 2024-08-10 08:42:14

什么对我有用?

将构建输出路径从 bin/x86/Debug 更改为 bin/Debug 对我有用。但仍然没有任何意义,因为我的平台目标设置为“x86”。因此,我决定更多地关注这个问题,并发现下拉列表“x86”中的平台选择并未反映项目配置文件中设置的“值”。

我在 VS 中卸载了该项目,在编辑器中打开 .csproj 文件以查看“平台”的值是什么。令我惊讶的是,它被设置为“任何 CPU”,而构建选项下的下拉列表显示“x86”。我所做的只是手动编辑 .csproj 文件以读取“x86”。

以下是解决步骤:

  • 右键单击​​ VS 项目
  • 卸载
  • 右键单击​​并编辑 .csproj 文件
  • 确保“平台”设置为正确的

What worked for me?

Changing the build output path from bin/x86/Debug to bin/Debug worked for me. But still did not make any sense since my Platform Target was set 'x86'. So I decided to dwell more to the issue and found out that Platform selection in the dropdown 'x86' did not reflect the 'Value' set in the project configuration file.

I unloaded the Project in VS, opened .csproj file in the editor to see what the value is for 'Platform'. To my surprise it is set to 'Any CPU' while the dropdown under the build options showed 'x86'. All I did was to manually edit the .csproj file to read 'x86'.

Here are steps to resolve:

  • Right click on VS project
  • Unload
  • Right Click and edit .csproj file
  • Make sure 'Platform' is set to the correct one
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文