我试图在我的Silverlight应用程序中使用第三方组件,当我试图创建控件的实例时,我得到了一个XamlParseException:
{System.Windows.Markup.XamlParseException: **Set property 'System.Windows.FrameworkElement.Style' threw an exception.** [Line: 0 Position: 0]
---> System.Windows.Markup.XamlParseException: **Elements in the same ResourceDictionary cannot have the same x:Key** [Line: 1739 Position: 47]
at MS.Internal.XcpImports.CreateFromXaml(UnmanagedMemoryStream stream, String sourceAssemblyName, boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers)
at System.Windows.Controls.Control.GetBuiltInStyle(IntPtr nativeTarget, IntPtr& nativeStyle)
--- End of inner exception stack trace ---
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at SpellCheckerSample.StandardSpellDialog.InitializeComponent()
at SpellCheckerSample.StandardSpellDialog..ctor()}我如何调试它呢?我如何知道文件行1739,位置47在什么位置?
发布于 2010-05-21 11:55:26
原来我的具体问题是ComponentOne组件只能在Silverlight4下工作,一旦我切换到目标SL4,一切都能正常工作。
发布于 2010-05-21 11:09:26
找起来可能有点麻烦。基本上,尝试从调试器收集尽可能多的详细信息。
查看XamlParseException.
在我写完这篇文章后,我意识到这个控件的构造函数确实在调用堆栈上,而且它是SpellCheckerSample。很可能是该控件的.XAML页面。如果您可以访问源代码,则文件名很可能类似于SpellCheckerSample.xaml.
错误本身是非常直接的,看起来像是在同一个ResourceDictionary中用相同的键定义了多个东西。下面的代码将导致这种情况的发生:
<Window.Resources>
<myConverters:BananaToCarrotConverter x:Key="StupidestConverterEver" />
<myConverters:BananaToAppleConverter x:Key="StupidestConverterEver" />
<Window.Resources>发布于 2014-02-19 19:05:40
检查你得到的ResourceDictionary引用--问题通常是其中之一出现了需要修复的错误。
如果你的异常是来自App的原因,它可能是你的合并目录之一,否则就是有问题的控件。
还要检查您是否没有遗漏样式的资源目录使用情况(如果您使用了ReSharper,则会有所帮助,因为您将在XAML设计时收到警告)。

https://stackoverflow.com/questions/2879312
复制相似问题