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

  • Home
  • SEARCH
  • 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 7672839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:22:38+00:00 2026-05-31T16:22:38+00:00

If I create a class that extends UserControl and want to set a default

  • 0

If I create a class that extends UserControl and want to set a default value for a DependencyProperty that is declared in UserControl, say FontSize, I can add a static constructor like the following:

static MyUserControl()
{
    UserControl.FontSizeProperty.OverrideMetadata(typeof(MyUserControl), 
new FrameworkPropertyMetadata(28.0));
}

Before I learned about the OverrideMetadata method, I used to override the property and set the DescriptionAttribute in the following way:

public new static readonly DependencyProperty FontSizeProperty = 
DependencyProperty.Register("FontSize", typeof(double), typeof(MyUserControl), 
new PropertyMetadata(28.0));

[Description("My custom description."), Category("Text")]
public new double FontSize
{
    get { return (double)GetValue(FontSizeProperty); }
    set { SetValue(FontSizeProperty, value); }
}

The DescriptionAttribute value is displayed as a popup tooltip in the Properties Window of Visual Studio when a user moves the mouse pointer over the relevant property name. My question is, is it possible to set the DescriptionAttribute value of this DependencyProperty in a similar way to overriding the metadata? Or will I have to keep the CLR getter/setter property and attribute declaration?

Many thanks in advance.

  • 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-31T16:22:39+00:00Added an answer on May 31, 2026 at 4:22 pm

    I found that I could access the DescriptionAttribute value of the inherited type property, but only from an instance constructor and not the static constuctor because I needed a reference to the control object. Also, I could not set it using this method as it was a read only property:

    AttributeCollection attributes = 
        TypeDescriptor.GetProperties(this)["FontSize"].Attributes;
    DescriptionAttribute attribute = 
        (DescriptionAttribute)attributes[typeof(DescriptionAttribute)];
    attribute.Description = "Custom description"; // not possible - read only property
    

    I then discovered that you can’t change declared attribute values at run time from these articles:

    1. Can attributes be added dynamically in C#?
    2. Programmatically add an attribute to a method or parameter

    I will therefore continue to declare the CLR wrapper properties with new DescriptionAttribute values and override the metadata in the static constructor just to set new default values.

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

Sidebar

Related Questions

I create class that extends LinerLayout and add many elements on view, also I
I want to create a class that initializes a timer which will be used
I'm trying to create a class that can instantiate arrays at runtime by giving
I'm trying to figure out the best way to create a class that can
I'm trying to create a class that extends input stream Clojure via gen-class .
I have create a class MyConnection that extends NSURLConnection. I have implemented some delegate
I have create a class that extends BaseAdapter . At the same time, tt
I need to create my own class that extends Hash and append the additional
If I create a class that extends WPF's ListBoxItem, create a list of these
I'm attempting to create a class that extends a CursorAdapter in order to display

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.