【发布时间】:2014-04-22 16:29:38
【问题描述】:
我创建了一个自定义 UserControl,它公开了一些 DependencyProperties,例如 HeaderTitle 和 HeaderTitleForeground
public partial class PageHeaderControl : UserControl
{
public string HeaderTitle
{
get { return (string)GetValue(HeaderTitleProperty); }
set { SetValue(HeaderTitleProperty, value); }
}
public static readonly DependencyProperty HeaderTitleProperty = DependencyProperty.Register("HeaderTitle", typeof(string), typeof(PageHeaderControl), new PropertyMetadata(""));
public string HeaderTitleForeground
{
get { return (string)GetValue(HeaderTitleForegroundProperty); }
set { SetValue(HeaderTitleForegroundProperty, value); }
}
public static readonly DependencyProperty HeaderTitleForegroundProperty = DependencyProperty.Register("HeaderTitleForeground", typeof(string), typeof(PageHeaderControl), new PropertyMetadata(""));
public PageHeaderControl()
{
InitializeComponent();
(this.Content as FrameworkElement).DataContext = this;
}
}
但是当我调试我的应用程序时,它会抛出一个异常,如下所示:
System.Exception occurred
_HResult=-2146233088
_message=Error HRESULT E_FAIL has been returned from a call to a COM component.
HResult=-2146233088
Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
Source=System.Windows
StackTrace:
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
InnerException:
但是自定义控件是正确绘制的。那么,我该如何解决呢?这是一个关键问题吗?
【问题讨论】:
标签: c# xaml user-controls windows-phone