Blend 3 在设计时找不到我的转换器/资源。(WPF)
我在将 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?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看起来您的 XAML 中有拼写错误:
Alubm
而不是Album
和BlentTest
而不是BlendTest
我猜测这些错误实际上是真正的编译器错误,并且纠正上面的两个拼写错误很可能会“修复”设计者。
编辑:
我看到的最有可能的候选者是您的转换器位于与 XAML 文件不同的项目中(但位于同一解决方案中)。如果是这种情况,请确保在 XAML 声明中指定程序集,并确保正确引用其他项目(使用 BlendTest)。即:
如果您引用在不同项目中定义的类型(带有命名空间),则程序集引用也需要存在。
It looks like you have typos in your XAML:
Alubm
instead ofAlbum
andBlentTest
instead ofBlendTest
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:
If your referring to a type (with namespace) defined in a different project, the assembly reference needs to exist, as well.
好吧,虽然我仍然不知道问题的原因。
解决方案如下:
我创建了一个新的代码库项目,并将所有控件和转换器移至此处。
我使用 XmlnsDefinition 属性来修饰程序集,以便每个程序集都对应于相同的命名空间。
修复所有引用。
瞧。
爱丽儿
Well, while the cause of the problem is still unknown to me.
The solution to the mess was as followed:
I've created a new Code Library project, and moved there all my controls and converters.
I used the XmlnsDefinition attribute to decorate the assembly so each was corresponding to the same namespace.
fixing all the references.
and Voilà.
Ariel
这个答案为我解决了这个问题:我将“平台目标”重置为“任何CPU”。
This answer fixed it for me: I reset the 'Platform Target' to 'Any CPU'.
什么对我有用?
将构建输出路径从 bin/x86/Debug 更改为 bin/Debug 对我有用。但仍然没有任何意义,因为我的平台目标设置为“x86”。因此,我决定更多地关注这个问题,并发现下拉列表“x86”中的平台选择并未反映项目配置文件中设置的“值”。
我在 VS 中卸载了该项目,在编辑器中打开 .csproj 文件以查看“平台”的值是什么。令我惊讶的是,它被设置为“任何 CPU”,而构建选项下的下拉列表显示“x86”。我所做的只是手动编辑 .csproj 文件以读取“x86”。
以下是解决步骤:
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: