【发布时间】:2016-03-28 09:37:49
【问题描述】:
我有一个自定义控件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(Object 组件,Uri resourceLocator,ComponentResourceLocation 组件资源位置)在 CurrencyExchangeUniversal.App.View.NationalBankPage.InitializeComponent() 在 CurrencyExchangeUniversal.App.View.NationalBankPage..ctor()
【问题讨论】:
-
Abc的类型是什么?
-
为
Abc添加了代码 -
似乎绑定是正确的。检查 OnItemsChanged 方法
标签: c# xaml win-universal-app