我有自定义控件LineChart
。代码xaml.cs:UWP未能在自定义控件中分配属性错误
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 }); }
}
在其他页面:
<controls:LineChart Stroke="{Binding Abc}" />
所有工作正常的代码Stroke="Green"
静线,但是当我使用Binding
,有错误的程序粉碎:
Windows.UI.Xaml.Markup.XamlParseException: The text associated with this error code could not be found.
Failed to assign to property CurrencyExchangeUniversal.App.Controls.LineChart.Stroke'. [Line: 102 Position: 41] at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation) at CurrencyExchangeUniversal.App.View.NationalBankPage.InitializeComponent() at CurrencyExchangeUniversal.App.View.NationalBankPage..ctor()
什么是ABC的类型? – Archana
为'Abc'添加代码 –
看起来像绑定是正确的。检查OnItemsChanged方法 – Archana