Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6201561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:34:37+00:00 2026-05-24T04:34:37+00:00

I have 2 custom controls as defined below: public class Icon : Control {

  • 0

I have 2 custom controls as defined below:

public class Icon : Control
{
    public Icon()
        : base()
    {
        DefaultStyleKey = typeof(Icon);
    }

    public static readonly DependencyProperty ColorProperty = DependencyProperty.Register("Color", typeof(SolidColorBrush), typeof(Icon), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
    public SolidColorBrush Color
    {
        get
        {
            return (SolidColorBrush)GetValue(ColorProperty);
        }
        set
        {
            SetValue(ColorProperty, value);
        }
    }
}

public class Rating : Control
{
    private StackPanel _panel;

    public Rating()
        : base()
    {
        DefaultStyleKey = typeof(Rating);
    }

    public static readonly DependencyProperty ColorProperty = DependencyProperty.Register("ColorProperty", typeof(SolidColorBrush), typeof(Rating), null);
    public SolidColorBrush Color
    {
        get
        {
            return (SolidColorBrush)GetValue(ColorProperty);
        }
        set
        {
            SetValue(ColorProperty, value);
            Debug.WriteLine(Name + " - Set Color");
        }
    }

    public override void OnApplyTemplate()
    {
        Debug.WriteLine(Name + " - On Apply Template");
        base.OnApplyTemplate();
    }
}

The UI for those controls are defined in a Generic.xaml:

<Style TargetType="lib:Icon">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="lib:Icon">
                <Ellipse Width="32" Height="32" Margin="4" Fill="{Binding Path=Color, RelativeSource={RelativeSource TemplatedParent}}"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="lib:Rating">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="lib:Rating">
                <StackPanel x:Name="Panel" Orientation="Horizontal">
                    <lib:Icon Color="{Binding Path=Color, RelativeSource={RelativeSource TemplatedParent}}"/>
                    <lib:Icon Color="{Binding Path=Color, RelativeSource={RelativeSource TemplatedParent}}"/>
                    <lib:Icon Color="{Binding Path=Color, RelativeSource={RelativeSource TemplatedParent}}"/>
                    <lib:Icon Color="{Binding Path=Color, RelativeSource={RelativeSource TemplatedParent}}"/>
                    <lib:Icon Color="{Binding Path=Color, RelativeSource={RelativeSource TemplatedParent}}"/>
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Now in my MainPage.xaml, i use the Rating control as follows:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <StackPanel Orientation="Horizontal" Grid.Row="0">
        <Button Content="Yellow" Click="ChangeDataContext"/>
    </StackPanel>
    <StackPanel Grid.Row="1">
        <lib:Rating Color="Red"/>
        <lib:Rating Name="MyRating" Color="{Binding Path=Color}"/>
    </StackPanel>
</Grid>

In the code-behind, i set the data-context as follows:

public partial class MainPage : PhoneApplicationPage
{
    public MainPage()
    {
        InitializeComponent();
        ColorData data = new ColorData() { Color = new SolidColorBrush(Colors.Cyan) };
        MyRating.DataContext = data;
    }

    private void ChangeDataContext(object sender, System.Windows.RoutedEventArgs e)
    {
        ColorData data = new ColorData() { Color = new SolidColorBrush(Colors.Yellow) };
        MyRating.DataContext = data;
    }
}

public class ColorData
{
    public SolidColorBrush Color { get; set; }
}

When i run this code, i receive AG_E_PARSER_BAD_PROPERTY_VALUE pointing to the Data-binding line in the MainPage.XAML.
Would someone know why this is so and how i can fix that?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:34:38+00:00Added an answer on May 24, 2026 at 4:34 am

    You’ve registered the wrong name for your Color property. Change

    public static readonly DependencyProperty ColorProperty = DependencyProperty.Register("ColorProperty", typeof(SolidColorBrush), typeof(Rating), null);
    

    to

    public static readonly DependencyProperty ColorProperty = DependencyProperty.Register("Color", typeof(SolidColorBrush), typeof(Rating), null);
    

    and it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom Dependency Property defined like so: public static readonly DependencyProperty MyDependencyProperty
I have two custom controls that are analogous to a node and the control
I have a custom control derived from Button: class MyControl : Button{} And suppose,
I have a few DependencyProperties defined in some custom user controls. I'd like for
I have a class ComponentItem which i simplified (pseudo code) below public class ComponentItem
I have custom control where i want to show some items. In generic.xaml defined
Basically, I have a custom templated control with a custom data container class. When
I have multiple custom controls used on a ASPX (and C#) page registered from
I have a number of custom controls that I am trying to enable designer
I have a container of custom controls each of which have 2 controls in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.