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?
This error indicates that an attribute has been applied to a property element which is not valid. In your case, this is the
x:Keyattribute on thecontrolsInputToolkit:ContextMenuService.ContextMenuelement. 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.