两次引用路径资源会导致崩溃 [英] Referencing a path resource twice causes a crash

查看:58
本文介绍了两次引用路径资源会导致崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我这不起作用:

Can anyone tell my this isn't working:

<Window
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	x:Class="test8.MainWindow"
	x:Name="Window"
	Title="MainWindow"
	Width="640" Height="480">
	
	<Window.Resources>
		<Path x:Key="myPath" Fill="White" Stretch="Fill" Stroke="Black" Width="90.25" Height="41.187" Data="M3,-26.5 L-40,-20 -25.5,-2.75 18.5,2.875 49.25,-13.3125 12.625,-12.3125 27.625,-37.3125 z"/>
	</Window.Resources>
	
	<Grid x:Name="LayoutRoot">
		<Button Margin="178,79,211,0" VerticalAlignment="Top" Height="84" Content="{StaticResource myPath}"/>
		
		<Button Margin="178,79,211,0" VerticalAlignment="Top" Height="84" Content="{StaticResource myPath}"/>
	</Grid>
</Window>




它构建,但运行时崩溃。

看起来特别奇怪我,因为sollowing工作完美:




It builds, but the crashes when run.

It seems especially weird to me since the sollowing works perfectly:

<Window
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	x:Class="test8.MainWindow"
	x:Name="Window"
	Title="MainWindow"
	Width="640" Height="480">
	
	<Window.Resources>
		<Path x:Key="myPath" Fill="White" Stretch="Fill" Stroke="Black" Width="90.25" Height="41.187" Data="M3,-26.5 L-40,-20 -25.5,-2.75 18.5,2.875 49.25,-13.3125 12.625,-12.3125 27.625,-37.3125 z"/>
	</Window.Resources>
	
	<Grid x:Name="LayoutRoot">
		<Button Margin="178,79,211,0" VerticalAlignment="Top" Height="84" Content="{StaticResource myPath}"/>
		
		<!-- Removing the following line is the only change here -->
		<!-- <Button Margin="178,79,211,0" VerticalAlignment="Top" Height="84" Content="{StaticResource myPath}"/> -->
	</Grid>
</Window>






推荐答案

这是生成的输出通过崩溃的应用程序:

建设项目:test8.sln,目标:建设中__________________________________________________
项目"G:\ CREATIVE \ Kunder \Sølund \Snoezelhuset\Interface\WPF\Tests\test8\test8.sln" (建立目标):

__________________________________________________项目"G:\ CREATIVE\Kunder\Sølund\Snoezelhuset \Interface\WPF \Tests\ test8 \test8.sln"正在建设"G:\ CREATIVE \ Kunder\Sølund\Snoezelhuset \Interface\WPF \Tests\test8 \\\ test8 \ test8.csproj" (默认目标):

c:\ WINDOWS \ MicroStoswork \ Framework \v3.5 \Csc.exe / noconfig / nowarn:1701,1702 / errorreport:prompt / warn :4 / define:DEBUG; TRACE / reference:" C:\Program Files \Reference Assemblies\Microsoft\Framework\v3.0 \ PresentationCore.dll" / reference:" C:\Program Files \Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll" / reference:" c:\Program Files \Reference Assemblies\Microsoft\Framework\v3.5 \ System.Core.dll" / reference:" c:\Program Files \Reference Assemblies\Microsoft \Framework\v3.5 \ System.Data.DataSetExtensions.dll" /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\\ \\ Systemystem /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll / reference:" c:\Program Files \ Reference Assemblies\Microsoft \Framework\v3.5\System.Xml.Linq.dll" / reference:" C:\Program Files \Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll" / debug + / debug:full / filealign:512 / optimize- /out:obj\Debug\test8.exe /resource:obj\Debug\test8.g.resources / target:winexe /win32icon:Application.ico App .xaml.cs属性\AssemblyInfo.cs MainWindow.xaml.cs" G:\ CREATIVE \ Kunder\Sølund\Snoezelhuset \Interface\WPF \Tests\test8 \ test8 \ objj \\ \\Debug\MainWindow.g.cs" "G:\ CREATIVE \ Kunder\Sølund\Snoezelhuset \Interface\WPF \Tests \ test8 \ test8 \obj \Debug \ App.g.cs"
test8 - > G:\ CREATIVE \ Kunder\Sølund\Snoezelhuset \Interface\WPF \Tests \ test8 \ test8 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
未处理的异常:System.Windows.Markup.XamlParseException:无法将属性"Content"中的值转换为"System.Object"类型的对象。指定的元素已经是另一个元素的逻辑子元素。首先断开它。标记文件'test8; component / mainwindow.xaml'中的对象'System.Windows.Controls.Button'出错。第15行位置69. ---> System.InvalidOperationException:指定的元素已经是另一个元素的逻辑子元素。首先断开它。
在System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
在MS.Internal.FrameworkObject.ChangeLogicalParent(DependencyObject newParent)
在System.Windows.FrameworkElement.AddLogicalChild(Object子))在System.Windows.Controls.ContentControl.OnContentChanged(Object oldContent,Object newContent)
在System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)
在系统中.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
在System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
在System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
在System.Windows .DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata metadata,EffectiveValueEntry oldEntry,EffectiveV alueEntry& newEntry,Boolean coerceWithDeferredReference,OperationType operationType)
在System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp,Object value,PropertyMetadata metadata,Boolean coerceWithDeferredReference,OperationType operationType,Boolean isInternal)
在System.Windows。 DependencyObject.SetValue(DependencyProperty dp,Object value)
在System.Windows.Markup.BamlRecordReader.SetDependencyValueCore(DependencyObject dependencyObject,DependencyProperty dependencyProperty,Object value)
在System.Windows.Markup.BamlRecordReader.SetDependencyValue(DependencyObject) dependencyObject,DependencyProperty dependencyProperty,Object value)
在System.Windows.Markup.BamlRecordReader.SetPropertyValue(Object o,PropertyDefinition propertyDefinition,Object value)
在System.Windows.Markup.BamlRecordReader.BaseReadOptimizedMarkupExtension(Object element, Int16 attributeId,PropertyDefinition propertyDefinit离子,对象值)
---内部异常堆栈跟踪的结束---在System.Windows.Markup.XamlParseException.ThrowException(String message,Exception innerException,Int32 lineNumber,Int32 linePosition,Uri baseUri) ,XamlObjectIds currentXamlObjectIds,XamlObjectIds contextXamlObjectIds,Type objectType)
在System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext,Int32 lineNumber,Int32 linePosition,String message,Exception innerException)
在System.Windows.Markup .BamlRecordReader.ThrowExceptionWithLine(String message,Exception innerException)
在System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type,Int16 typeId,Boolean throwOnFail)
在System.Windows.Markup.BamlRecordReader.GetElementAndFlags( BamlElementStartRecord bamlElementStartRecord,Object&元素,ReaderFlags&旗帜,类型& delayCreatedType,Int16& delayCreatedTypeId)
在System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
在System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
在System.Windows.Markup.BamlRecordReader .ReadRecord(BamlRecord bamlRecord)
在System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
在System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
在System.Windows.Markup .TreeBuilder.Parse()
在System.Windows.Markup.XamlReader.LoadBaml(Stream stream,ParserContext parserContext,Object parent,Boolean closeStream)
在System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream,ParserContext) pc)
在System.Windows.Application.LoadComponent(Uri resourceLocator,Boolean bSkipJournaledProperties)
在System.Windows.Application.DoStartup()
在System.Windows.Application。< .ctor > b__0(Object unused)
在System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,Object args,Boolean isSingleParameter)
在System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source,Delegate) callback,Object args,Boolean isSingleParameter,Delegate catchHandler)
在System.Windows.Threading.Dispatcher.WrappedInvoke(委托回调,Object args,Boolean isSingleParameter,Delegate catchHandler)
在System.Windows.Threading.DispatcherOperation .InvokeImpl()
在System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
在System.Threading.ExecutionContext.runTryCode(Object userData)
在System.Runtime.CompilerServices.RuntimeHelpers .ExecuteCodeWithGuaranteedCleanup(TryCode代码,CleanupCode,backoutCode,Object userData)
在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态)
在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)
在System.Windows.Threading.DispatcherOperation.Invoke()
在System.Windows.Threading.Dispatcher.ProcessQueue()
在System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&处理)在MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean& handling)
在MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback,Object args,Boolean isSingleParameter)
在System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source,Delegate callback,Object args,Boolean isSingleParameter,Delegate catchHandler) )在System.Windows.Threading.Dispatcher.WrappedInvoke(委托回调,Object args,Boolean isSingleParameter,Delegate catchHandler)
在System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority,TimeSpan timeout,Delegate)方法,Object args,Boolean isSingleParameter)
在System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority,Delegate方法,Object arg)
在MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg) ,IntPtr wParam,IntPtr lParam)
在MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
在System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame框架)
在System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame框架)
在System.Windows.Threading.Dispatcher .Run()
在System.Windows.Application.RunDispatcher(Object ignore)
在System.Windows.Application.RunInternal(窗口窗口)
在System.Windows.Application.Run(Window窗口)
在System.Windows.Application.Run()
在test8.App.Main()

This is the output generated by the crashed application:


Build project: test8.sln, Targets: Build
__________________________________________________
Project "G:\CREATIVE\Kunder\Sølund\Snoezelhuset\Interface\WPF\Tests\test8\test8.sln" (Build target(s)):

__________________________________________________
Project "G:\CREATIVE\Kunder\Sølund\Snoezelhuset\Interface\WPF\Tests\test8\test8.sln" is building "G:\CREATIVE\Kunder\Sølund\Snoezelhuset\Interface\WPF\Tests\test8\test8\test8.csproj" (default targets):

c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll" /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\test8.exe /resource:obj\Debug\test8.g.resources /target:winexe /win32icon:Application.ico App.xaml.cs Properties\AssemblyInfo.cs MainWindow.xaml.cs "G:\CREATIVE\Kunder\Sølund\Snoezelhuset\Interface\WPF\Tests\test8\test8\obj\Debug\MainWindow.g.cs" "G:\CREATIVE\Kunder\Sølund\Snoezelhuset\Interface\WPF\Tests\test8\test8\obj\Debug\App.g.cs"
test8 -> G:\CREATIVE\Kunder\Sølund\Snoezelhuset\Interface\WPF\Tests\test8\test8\bin\Debug\test8.exe
The build has successfully completed.
Unhandled Exception: System.Windows.Markup.XamlParseException: Cannot convert the value in attribute 'Content' to object of type 'System.Object'. Specified element is already the logical child of another element. Disconnect it first.  Error at object 'System.Windows.Controls.Button' in markup file 'test8;component/mainwindow.xaml' Line 15 Position 69. ---> System.InvalidOperationException: Specified element is already the logical child of another element. Disconnect it first.
   at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
   at MS.Internal.FrameworkObject.ChangeLogicalParent(DependencyObject newParent)
   at System.Windows.FrameworkElement.AddLogicalChild(Object child)
   at System.Windows.Controls.ContentControl.OnContentChanged(Object oldContent, Object newContent)
   at System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Markup.BamlRecordReader.SetDependencyValueCore(DependencyObject dependencyObject, DependencyProperty dependencyProperty, Object value)
   at System.Windows.Markup.BamlRecordReader.SetDependencyValue(DependencyObject dependencyObject, DependencyProperty dependencyProperty, Object value)
   at System.Windows.Markup.BamlRecordReader.SetPropertyValue(Object o, PropertyDefinition propertyDefinition, Object value)
   at System.Windows.Markup.BamlRecordReader.BaseReadOptimizedMarkupExtension(Object element, Int16 attributeId, PropertyDefinition propertyDefinition, Object value)
   --- End of inner exception stack trace ---
   at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
   at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
   at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
   at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
   at System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId)
   at System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
   at System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
   at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
   at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
   at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
   at System.Windows.Markup.TreeBuilder.Parse()
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
   at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__0(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
   at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at test8.App.Main()


这篇关于两次引用路径资源会导致崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆