4

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()

3
  • What is the type of Abc?
    – Archana
    Mar 28, 2016 at 9:52
  • Added code for Abc Mar 28, 2016 at 9:55
  • Seems like Binding is proper. Check OnItemsChanged method
    – Archana
    Mar 28, 2016 at 10:09

1 Answer 1

3

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)));
1
  • One problem on StackOverflow that happens to me way too often: I did not make the same mistake as the asker, and I still have the same problem. Since this question is "replied" I don't seem to find a solution now :( Apr 19, 2017 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.