Reputation: 239
I have a custom control LineChart
. Code in 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); }
}
In view model class:
public Brush Abc
{
get { return new SolidColorBrush(new Color() {A = 123, B = 123, G = 23, R = 12 } ); }
}
In other page:
<controls:LineChart Stroke="{Binding Abc}" />
All works fine with static line of code Stroke="Green"
, but when I use Binding
, program crushed with error:
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()
Upvotes: 4
Views: 1678
Reputation: 17865
You have made a mistake in your DependencyProperty.Register
call. The first argument value should be "Stroke"
, not "StrokeProperty"
:
public static readonly DependencyProperty StrokeProperty =
DependencyProperty.Register("Stroke", typeof(Brush), typeof(LineChart), new PropertyMetadata(new SolidColorBrush(),
new PropertyChangedCallback(OnItemsChanged)));
Upvotes: 3