UWP无法在自定义控件中分配属性错误

我有一个自定义控件LineChart 。 xaml.cs中的代码:

 public static readonly DependencyProperty StrokeProperty = DependencyProperty.Register("StrokeProperty", typeof(Brush), typeof(LineChart), new PropertyMetadata(new SolidColorBrush(), new PropertyChangedCallback(OnItemsChanged))); public Brush Stroke { get { return (Brush)GetValue(StrokeProperty); } set { SetValue(StrokeProperty, value); } } 

在视图模型类中:

 public Brush Abc { get { return new SolidColorBrush(new Color() {A = 123, B = 123, G = 23, R = 12 } ); } } 

在其他页面中:

  

所有工作都可以正常使用静态代码行Stroke="Green" ,但是当我使用Binding ,程序会被错误地压缩:

Windows.UI.Xaml.Markup.XamlParseException:找不到与此错误代码关联的文本。

无法分配给属性CurrencyExchangeUniversal.App.Controls.LineChart.Stroke’。 位于CurrencyExchangeUniversal.App.View.NationalBankPage的CurrencyExchangeUniversal.App.View.NationalBankPage.InitializeComponent()的Windows.UI.Xaml.Application.LoadComponent(对象组件,Uri resourceLocator,ComponentResourceLocation componentResourceLocation)的[行:102位置:41]构造函数()

你在DependencyProperty.Register调用中犯了一个错误。 第一个参数值应为"Stroke" ,而不是"StrokeProperty"

 public static readonly DependencyProperty StrokeProperty = DependencyProperty.Register("Stroke", typeof(Brush), typeof(LineChart), new PropertyMetadata(new SolidColorBrush(), new PropertyChangedCallback(OnItemsChanged)));