I иногда получают следующее исключение для моего пользовательского элемента управления:
XamlParseException occurred
Unknown attribute Points in element SectionClickableArea [Line: 10 Position 16]
Трассировка стека:
{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()}
Объявление элемента, где это происходит, выглядит следующим образом (конечно, определен обработчик события , на который есть ссылка):
<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"/>
Это часть кода 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); }
}
Я использую этот элемент управления для чего-то вроде кнопки в форме многоугольника. Поэтому я наследую от кнопки. У меня были подобные проблемы (E_AG_BAD_PROPERTY_VALUE
для другой DependencyProperty
строки типа, в соответствии с указанными строкой и столбцом и т. Д.) С этим элементом управления в течение нескольких недель, но я абсолютно не знаю, почему.
Еще одно исключение для того же элемента управления произошло сегодня утром для другого пользователя (взято из журнала и переведено с немецкого):
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()
Внутреннее исключение:
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)
Есть идеи, что не так с контролем или что я могу сделать, чтобы найти источник этих исключений? Как я уже сказал, эти проблемы возникают только каждые несколько десятков раз, когда создается экземпляр элемента управления.