我有一个自定义控件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 } ); }
}
在其他页面中:
<controls:LineChart Stroke="{Binding Abc}" />
静态代码行一切正常Stroke="Green"
,但是当我使用Binding
,程序因错误而崩溃:
Windows.UI.Xaml.Markup.XamlParseException:与关联的文本
无法找到此错误代码。
无法分配给属性
CurrencyExchangeUniversal.App.Controls.LineChart.Stroke'。 [线路:102
位置:41]位于Windows.UI.Xaml.Application.LoadComponent(对象
组件、Uri 资源定位器、ComponentResourceLocation
组件资源位置)位于
CurrencyExchangeUniversal.App.View.NationalBankPage.InitializeComponent()
在CurrencyExchangeUniversal.App.View.NationalBankPage..ctor()
你犯了一个错误DependencyProperty.Register
称呼。第一个参数值应该是"Stroke"
, not "StrokeProperty"
:
public static readonly DependencyProperty StrokeProperty =
DependencyProperty.Register("Stroke", typeof(Brush), typeof(LineChart), new PropertyMetadata(new SolidColorBrush(),
new PropertyChangedCallback(OnItemsChanged)));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)