【问题标题】:System.Windows.Media.SolidColorBrush Must Have IsFrozen set to False to edit errorSystem.Windows.Media.SolidColorBrush 必须将 IsFrozen 设置为 False 才能编辑错误
【发布时间】:2012-06-09 17:36:14
【问题描述】:

我有一个 WPF 应用程序,我在其中修改了许多控件的模板。在许多不同的情况下,我得到以下堆栈跟踪:

Specified value of type 'System.Windows.Media.SolidColorBrush' must have IsFrozen set to false to modify.
Specified value of type 'System.Windows.Media.SolidColorBrush' must have IsFrozen set to false to modify. (Exception class InvalidOperationException)

   at System.Windows.Markup.XamlReader.RewrapException(Exception e, Uri baseUri)
   at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
   at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
   at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
   at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
   at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
   at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
   at System.Windows.FrameworkElement.ApplyTemplate()
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
   at System.Windows.Interop.HwndTarget.OnResize()
   at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(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, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

我没有编写任何代码来尝试更改任何画笔的值。而且我不知道哪个控件正在产生错误。我怀疑问题出在我修改的其中一个模板上,但我不知道是哪一个。

我不知道如何跟踪和调试它。有人有什么想法吗?

【问题讨论】:

  • 讨厌!我不具体知道如何解决您的问题,但是面对这种情况,我可能会更改 Debug |例外 |要抛出的 CLR 异常,然后在 IDE 中运行应用程序,当异常命中时,请查看自动和本地,以尝试确定有问题的模板是什么。

标签: wpf xaml


【解决方案1】:

我很幸运得到了这个。

我注意到错误出现在应用程序的两个不同屏幕上。它们唯一的共同点是 Telerik 的 RadGridView 控件。我对该控件进行了一些自定义修改,以支持将调色板从“白天模式”更改为“夜间模式”。

我不知道我做了什么,但是我从 app.xaml 文件中删除了自定义模板,错误就消失了。然后我在 Expression Blend 中重新生成了模板,只替换了我所做的颜色更改的 Setter。并且错误仍然消失了!

我怀疑我可能在实现“夜间模式”的过程中升级了 Telerik 库,并且我有一个过时的控件模板。无论如何,错误已经消失了,至少现在是这样。

【讨论】:

    猜你喜欢
    • 2021-01-14
    • 2017-05-19
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多