Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按钮样式在运行时工作,但VisualStudio在设计时显示错误_C#_Wpf_Xaml_Visual Studio 2012 - Fatal编程技术网

C# 按钮样式在运行时工作,但VisualStudio在设计时显示错误

C# 按钮样式在运行时工作,但VisualStudio在设计时显示错误,c#,wpf,xaml,visual-studio-2012,C#,Wpf,Xaml,Visual Studio 2012,我使用以下类和DependencyProperty允许样式为按钮设置图像: public static class ImageButton { public static readonly DependencyProperty ImageProperty = DependencyProperty.RegisterAttached("Image", typeof(ImageSource), typeof(ImageButton),

我使用以下类和DependencyProperty允许样式为按钮设置图像:

public static class ImageButton
{
    public static readonly DependencyProperty ImageProperty = 
                  DependencyProperty.RegisterAttached("Image", typeof(ImageSource), typeof(ImageButton),
                                                                                                    new FrameworkPropertyMetadata((ImageSource)null));
    public static ImageSource GetImage(DependencyObject obj)
    {
        return (ImageSource)obj.GetValue(ImageProperty);
    }

    public static void SetImage(DependencyObject obj, ImageSource value)
    {
        obj.SetValue(ImageProperty, value);
    }
}
我已经定义了以下样式(在ImageButton.xaml中):


最后,为了使用它,我有这样的东西:

<Button Width="32"
        Height="32"
        Style="{StaticResource ImageButtonStyle}"
        vcontrols:ImageButton.Image="/Images/someimage.png"/>

当我编译和执行应用程序时,一切正常。 该按钮获取图像并使用样式中定义的动画

然而,在设计时,VisualStudio似乎无法将其可视化,并且 XAML编辑器在整个按钮定义下显示扭曲的线条

错误信息显示:

前缀“vControl”未映射到命名空间

这是指在样式中使用vControl。 如果在此处更改名称,错误也会更改, 因此,它与在使用按钮的窗口/用户控件中选择的名称无关


是什么导致了这种情况?有没有办法修复它,使其在设计时也能正常工作?

更新2:


此问题仅适用于VS2012 designer(在VS2010中工作正常),并且已在修补程序中修复。

是否尝试将名称空间声明添加到XAML文档根元素?也许Visual Studio只在那里查找声明?请尝试将程序集位添加到命名空间声明中。。。xmlns:vcontrolls=“clr名称空间:Vialis.Led.LedControl5.Controls;assembly=?”您好,程序集与应用程序相同(起初它是一个外部组件,但我认为将控件移动到同一个组件中可能会解决它…它没有解决问题。显式添加“;assembly=Vialis.Led.LedControl5”也没有帮助,这只会让事情变得更糟。当我读到你的问题时,tom想到的第一件事与MaLio的评论相同。你的意思是什么“那只会让事情变得更糟”?程序集实际上就是整个“Vialis.Led.LedControl5”@TimothyP,我刚刚用新的WPF应用程序项目测试了您的代码块,一切看起来都很好,并且在VS2010中工作正常(据我所知)-图像按钮在设计模式下看起来也不错。是否需要我发布测试项目中的完整代码(它将是您代码的95%,来自自动生成的项目模板的5%)?很抱歉这么晚才回复您。无论如何,这一定是VS2012中的一个错误,因为我得到了完全相同的异常。@TimothyP,我已经用VS2012更新2检查了它-问题已经存在。根据类似的投诉,您是对的-我相信这是VS2012问题。好消息-它已经在中修复了!:)@TimothyP,我可以在几分钟前在我的机器上测试并确认此设计时间问题最终得到解决。顺便说一句,您只需要VS2012.3 RC.exe(1.3 MB)web安装程序。现在安装,会让您知道:)
<Button Width="32"
        Height="32"
        Style="{StaticResource ImageButtonStyle}"
        vcontrols:ImageButton.Image="/Images/someimage.png"/>