ContextMenu静态资源编译错误
我创建了一个带有 ContextMenu 属性的 Silverlight 控件。我还创建了一个 ContextMenu 静态资源,我想将其添加到控件中,但出现编译错误。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controlsInputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" >
<controlsInputToolkit:ContextMenuService.ContextMenu x:Key="FilterableTreeViewContextMenu">
<controlsInputToolkit:ContextMenu>
<controlsInputToolkit:MenuItem Header="New" />
</controlsInputToolkit:ContextMenu>
</controlsInputToolkit:ContextMenuService.ContextMenu>
</ResourceDictionary>
错误: 解析规则 PropertyElement ::= 中出现意外的 ATTRIBUTE。属性内容? ENDTAG..
有什么想法吗?
I've created a Silverlight control with a ContextMenu property. I've also created a ContextMenu static resource, which one I want to add to the control, but I get a compile error.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controlsInputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" >
<controlsInputToolkit:ContextMenuService.ContextMenu x:Key="FilterableTreeViewContextMenu">
<controlsInputToolkit:ContextMenu>
<controlsInputToolkit:MenuItem Header="New" />
</controlsInputToolkit:ContextMenu>
</controlsInputToolkit:ContextMenuService.ContextMenu>
</ResourceDictionary>
The error:
Unexpected ATTRIBUTE in parse rule PropertyElement ::= . PROPERTYELEMENT Content? ENDTAG..
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此错误表明属性已应用于无效的属性元素。在您的例子中,这是
controlsInputToolkit:ContextMenuService.ContextMenu
元素上的x:Key
属性。您需要将其删除。您可以通过元素名称中包含的句点来标识 XAML 中的属性元素。名称中句点前面的部分是类的名称,后面的部分是该类的属性。此类元素中不允许使用属性。
您的 XAML 足够紧凑,让我可以轻松找到问题。如果此错误发生在更大的 XAML 文件中,则可以在 Visual Studio 中使用以下正则表达式来定位问题。只需确保选中“查找和替换”对话框中的“使用”复选框,然后在组合框中选择“正则表达式”即可。
\<:Al@.:Al@ :Al@=\".@\":b@>
如果您需要调整表达式,则 有关正则表达式语法的 MSDN 文档 将很有用。
This error indicates that an attribute has been applied to a property element which is not valid. In your case, this is the
x:Key
attribute on thecontrolsInputToolkit:ContextMenuService.ContextMenu
element. You will need to remove it.You can identify property elements in XAML by the period that is included within the name of the element. The part of the name prior to the period is the name of a class and the part that follows is a property on that class. Attributes are not allowed within such elements.
Your XAML was compact enough for me to easily find the problem. If this error occurs within a much larger XAML file, then the following regular expression can be used within Visual Studio to locate the problem. Just make sure to check the 'Use' checkbox in the 'Find and Replace' dialog and select 'Regular Expressions' in the combo box.
\<:Al@.:Al@ :Al@=\".@\":b@>
If you need to adjust the expression then the MSDN documentation on regular expression syntax will be useful.