提问人:StayOnTarget 提问时间:5/6/2022 更新时间:5/6/2022 访问量:436
XamlParseException:“”不是属性“RuntimeVisibility”的有效值?
XamlParseException: '' is not a valid value for property 'RuntimeVisibility'?
问:
编辑 WPF 自定义控件时,Visual Studio 2019 中的设计视图遇到以下错误:
(整个异常详细信息如下)。
网络搜索没有发现任何有用的东西,尽管还有其他措辞相似的“不是有效值”的消息,但它们似乎各不相同。我甚至找不到术语“RuntimeVisibility”几乎与 WPF 相关。RuntimeVisibility
因此,我尝试通过附加到单独的 VS2019 实例中的 XDesProc 来调试 VS2019 设计器进程。通过启用所有异常的捕获,当相关控件加载到设计器中时,它确实会中断。但它在任何用户级代码中都没有失败;问题出现在框架深处的某个地方,该堆栈帧上的调试信息对我来说毫无意义。
我正在寻找一种方法或建议来追踪此问题的根本原因。虽然这在设计器中很烦人,但我更担心这是否会导致运行时出错。如前所述,这个神秘的属性似乎不是设计师特有的问题。RuntimeVisibility
完整的异常信息:
XamlParseException: '' is not a valid value for property 'RuntimeVisibility'.
StackTrace
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()
InnerException: '' is not a valid value for property 'RuntimeVisibility'.
ArgumentException: '' is not a valid value for property 'RuntimeVisibility'.
StackTrace
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
InnerException: None
答:
在我放弃调试 XDesProc 之后,我诉诸于在 XAML 中注释内容,只是凭直觉查看是否可以找到问题。我并不特别知道它起源于 XAML,但事实证明确实如此。
通过“由外而内”(即注释掉 XAML 的几乎整个正文,然后逐渐添加回内容),我能够将其缩小到一行,当删除该行时,该行也消除了错误:
<Canvas
ToolTipService.IsEnabled="{c:Binding ShowToolTip}"
Visibility="{c:Binding IsVisible}"
>
其中指:c:Binding
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
(https://github.com/Alex141/CalcBinding)
删除该属性后,错误将消失。Visibility
这里所做的是在视图模型中的属性和适当的值之间自动转换。这通常工作正常,但我可以用正常绑定和转换器替换它来解决此问题。c:Binding
bool
Visibility
下一个:尝试制作有异常的计算器
评论