我有自定義控件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