I sometimes get the following exception for a custom control of mine:
XamlParseException occurred
Unknown attribute Points in element SectionClickableArea [Line: 10 Position 16]
The stack trace:
{System.Windows.Markup.XamlParseException: Unknown attribute Points on element SectionClickableArea. [Line: 10 Position: 16]
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at SomeMainDialog.InitializeComponent()
at SomeMainDialog..ctor()}
The element declaration where this happens looks like this (the event handler referenced here is defined, of course):
<l:SectionClickableArea x:Name="SomeButton"
Points="528,350, 508,265, 520,195, 515,190, 517,165, 530,120, 555,75, 570,61, 580,60, 600,66, 615,80, 617,335, 588,395, 550,385, 540,390, 525,393, 520,385"
Click="SomeButton_Click"/>
This is part of the code of SectionClickableArea
:
public partial class SectionClickableArea : Button {
public static readonly DependencyProperty PointsProperty
= DependencyProperty.Register("Points", typeof(PointCollection), typeof(SectionClickableArea),
new PropertyMetadata((s, e) => {
SectionClickableArea area = (SectionClickableArea) s;
area.areaInfo.Points = (PointCollection) e.NewValue;
area.UpdateLabelPosition();
}));
public PointCollection Points {
get { return (PointCollection) GetValue(PointsProperty); }
set { SetValue(PointsProperty, value); }
}
I use this control for something like a polygon-shaped button. Therefore I'm inheriting from button. I've had similar problems (E_AG_BAD_PROPERTY_VALUE
on another DependencyProperty
of type string, according to the line and column given, etc) with this control for weeks, but I have absolutely no idea why.
Another exception for the same control occurred this morning for another user (taken from a log and translated from German):
Type: System.InvalidCastException Message: The object of type System.Windows.Controls.ContentControl could not be converted to type [...]SectionClickableArea. at SomeOtherMainDialog.InitializeComponent()
at SomeOtherMainDialog..ctor()
Inner exception:
Type: System.Exception Message: An HRESULT E_FAIL error was returned when calling COM component at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, DependencyObject doh)
at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper doh, DependencyProperty property, Object obj)
at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at System.Windows.Controls.Control.set_DefaultStyleKey(Object value)
at System.Windows.Controls.ContentControl..ctor()
at System.Windows.CoreTypes.GetCoreWrapper(Int32 typeId)
at MS.Internal.ManagedPeerTable.EnsureManagedPeer(IntPtr unmanagedPointer, Int32 typeIndex, Type type, Boolean preserveManagedObjectReference)
at MS.Internal.ManagedPeerTable.EnsureManagedPeer(IntPtr unmanagedPointer, Int32 typeIndex, Type type)
at MS.Internal.ManagedPeerTable.GetManagedPeer(IntPtr nativeObject)
at MS.Internal.FrameworkCallbacks.SetPropertyAttribute(IntPtr nativeTarget, String attrName, String attrValue, String attachedDPOwnerNamespace, String attachedDPOwnerAssembly)
Any ideas what's wrong with the control, or what I can do to find the source of these exceptions? As I said, these problem occur only every few dozen times the control is instantiated.