当前位置: 首页 > 编程语言 > C#

WPF中绑定时出现Markup.IStyle.Connector.Connect错误分享

时间:2023-04-11 11:48:48 C#

WPF中绑定时出现Markup.IStyle.Connector.Connect错误好时光。我在WPF中遇到数据绑定问题。如果我使用绑定:在下面的代码中,我在某些计算机上遇到Markup.IStyle.Connector.Connect错误。我不懂为什么。如果您遇到这种行为或对此有一些想法。请分享。调用栈:Camdrive.UpgradeTools.MainWindow.System.Windows.Markup.IStyleConnector.Connect(Int32connectionId,Objecttarget)c:DevelopCamdrive.UtilsCamdrive.UpgradeToolsCamdrive.UpgradeToolsMainWindow.xaml:строка75×System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReadertemplateReader,XamlObjectWritercurrentWriter)×System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriterobjectWriter)×System.Windows.FrameworkTemplate.LoadTemplateContainer(System.Windows.FrameworkTemplate.LoadTemplateContainer),IComponentConnectorcomponentConnector,IStyleConnectorstyleConnector,List`1affectedChildren,UncommonField`1templatedNonFeChildrenField)×System.Windows.FrameworkTemplate.LoadContent(DependencyObjectcontainer,List`1affectedChildren)×System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1dataField,DependencyObject容器,框架元素工厂templateRoot,Int32lastChildIndex,HybridDictionarychildIndexFromChildID,FrameworkTemplateframeworkTemplate)×System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1templateDataField,FrameworkElementcontainer)×System.Windows.FrameworkElement.ApplyTemplate()×System.Windows.FrameworkElement.MeasureCore(SizeavailableSize)×System.Windows.UIElement.Measure(大小可用大小)×MS.Internal.Helper.MeasureElementWithSingleChild(UIElement元素,大小约束)×System.Windows.Controls.ContentPresenter.MeasureOverride(大小约束)×System.Windows.FrameworkElement.MeasureCore(可用大小)×System.Windows.UIElement.Measure(可用大小)×System.Windows.Controls.Border.MeasureOverride(大小约束)×System.Windows.FrameworkElement.MeasureCore(可用大小)×System.Windows.UIElement.Measure(可用大小)×System.Windows.Controls.Control.MeasureOverride(大小约束)×System.Windows.Controls.DataGridCell.MeasureOverride(大小约束)×System.Windows.FrameworkElement.MeasureCore(可用大小)×System.Windows.UIElement.Measure(可用大小)×System.Windows.Controls.DataGridCellsPanel.MeasureChild(UIElement子项,大小约束)System.Windows.Controls.DataGridCellsPanel.GenerateChild(IItemContainerGenerator生成器,大小约束,DataGridColumn列,Int32和childIndex,Size和childSize)System.Windows.Controls.DataGridCellsPanel.GenerateChildren(IItemContainerGenerator生成器,Int32startIndex,Int32endIndex,大小约束)System.Windows.Controls.DataGridCellsPanel.GenerateAndMeasureChildrenForRealizedColumns(大小约束)×System.Windows.Controls.DataGridCellsPanel.MeasureOverride(大小约束)×System.Windows.FrameworkElement.MeasureCore(可用大小)×System.Windows.UIElement.Measure(可用大小)×MS.Internal.Helper.MeasureElementWithSingleChild(UIElementel元素,大小约束)×System.Windows.Controls.ItemsPresenter.MeasureOverride(大小约束)×System.Windows.FrameworkElement.MeasureCore(可用大小)×System.Windows.UIElement.Measure(可用大小)×System.Windows.Controls。Control.MeasureOverride(大小约束)×System.Windows.Controls.Primitives.DataGridCellsPresenter.MeasureOverride(可用大小)×System.Windows.FrameworkElement.MeasureCore(可用大小)×System.Windows.UIElement.Measure(可用大小)×系统。Windows.Controls.Grid.MeasureCell(Int32cell,BooleanforceInfinityV)×System.Windows.Controls.Grid.MeasureCellsGroup(Int32cellsHead,SizereferenceSize,BooleanignoreDesiredSizeU,BooleanforceInfinityV)×System.Windows.Controls.Grid.MeasureOverride(Sizeconstraint)×System.Windows.FrameworkElement.MeasureCore(可用大小)×System.Windows.UIElement.Measure(可用大小)×System.Windows.Controls.Border.MeasureOverride(大小constraint)×System.Windows.FrameworkElement.MeasureCore(可用大小)×System.Windows.UIElement.Measure(可用大小)×System.Windows.Controls.Control.MeasureOverride(大小约束)×System.Windows.FrameworkElement.MeasureCore(大小availableSize)×System.Windows.UIElement.Measure(可用大小)×System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(大小约束)×System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(大小约束)×System.Windows.FrameworkElement.MeasureCore(可用大小)×System.Windows.UIElement.Measure(可用大小)×System.Windows.ContextLayoutManager.UpdateLayout()×System.Windows.ContextLayoutManager.UpdateLayoutCallback(Objectarg)×System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()×System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()×System.Windows.Media.MediaContext.RenderMessageHandlerCore(ObjectresizedCompositionTarget)System.Windows.Media.MediaContext.RenderMessageHandler(ObjectresizedCompositionTarget)System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegatecallback,Objectargs,Int32numArgs)MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Objectsource,委托方法、对象参数、Int32numArgs、委托catchHandler)×System.Windows.Threading.DispatcherOperation.InvokeImpl()×System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(对象状态)×System.Threading.ExecutionContext.runTryCode(对象用户数据)System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode代码,CleanupCodebackoutCode,ObjectuserData)System.Threading.ExecutionContext.RunInternal(ExecutionContextexecutionContext,ContextCallback回调,对象状态)System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallback回调、对象状态、布尔值ignoreSyncCtx)вSystem.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallbackcallback,Objectstate)×System.Windows.Threading.DispatcherOperation.Invoke()×System.Windows.Threading.Dispatcher.ProcessQueue()×System.Windows.Threading.Dispatcher。WndProcHook(IntPtrhwnd,Int32msg,IntPtrwParam,IntPtrlParam,Boolean&handled)×MS.Win32.HwndWrapper.WndProc(IntPtrhwnd,Int32msg,IntPtrwParam,IntPtrlParam,Boolean&handled)×MS.Win32.HwndOpatSubclass.DispatSubclass.对象o)System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegatecallback,Objectargs,Int32numArgs)MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Objectsource,Delegatemethod,Objectargs,Int32numArgs,DelegatecatchHandler)System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority优先级,TimeSpan超时,委托方法,Objectargs,Int32numArgs)-MS.Win32.HwndSubclass.SubclassWndProc(IntPtrhwnd,Int32msg,IntPtrwParam,IntPtrlParam)×MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&msg)×System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame框架)×System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame框架)×System.Windows.Application.RunDispatcher(对象忽略)×System.Windows.Application.RunInternal(窗口窗口)×System.Windows.Application.Run(窗口窗口)×System.Windows.Application.Run()×Camdrive.UpgradeTools。App.Main()-C:DevelopCamdrive.UtilsCamdrive.UpgradeToolsCamdrive.UpgradeToolsobjx86DebugApp.g.cs:строка0-System.AppDomain._nExecuteAssembly(RuntimeAssemblyassembly,String[]args)-System.AppDomain.ExecuteAssembly(StringassemblyFile,EvidenceassemblySecurity,String[]args)-Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()-System.Threading.ThreadHelper.ThreadStart_Context(对象状态)-System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,CcontextCallbackcallback,Objectstate,BooleanignoreSyncCtx)×System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallbackcallback,Objectstate)×System.Threading.ThreadHelper.ThreadStart()很可能是因为嵌套模板:CellTemplate->DataTemplate–>...->TreeView->TreeView.ItemTemplate->DataTemplateReferencethis:Thiserrorrequiresatemplatewithinatemplate查看此问题的好方法“模板就像方括号,引号方括号”模板XAML未创建,但保存并保存稍后运行。所以错误是:嵌套括号有问题。示例中:应用外部模板时,内部模板仍然被引用。但是,我们仍然为所有XAML调用IStyleConnector.Connect()(当我们单击内括号/引号时我们不会停止)并且没有TextBlock实例,所以我们崩溃了。由于优化的模板共享,repro发生了奇怪的事情。例如,如果您删除:Style="{StaticResourceTextBlockStyle}"错误消失,因为TextBlock在模板优化器中变得可共享。解决方法:最好的解决方案是将内部模板移至资源。尝试在资源中移动TreeView.ItemTemplate。以上就是C#学习教程的全部内容:Markup.IStyle.Connector.ConnecterrorwhenbindinginWPF.收藏不代表立场,如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: