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 8740573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:09:11+00:00 2026-06-13T11:09:11+00:00

i have a customcontrol static CustomControl1() { DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1))); } public List<string> MyProperty

  • 0

i have a customcontrol


    static CustomControl1()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new     FrameworkPropertyMetadata(typeof(CustomControl1)));
    }

    public List<string> MyProperty
    {
        get { return (List<string>)GetValue(MyPropertyProperty); }
        set { SetValue(MyPropertyProperty, value); }
    }
    public static readonly DependencyProperty MyPropertyProperty =
        DependencyProperty.Register("MyProperty", typeof(List<string>), 
                                                   typeof(CustomControl1), 
                                                   new UIPropertyMetadata(new List<string>()));        

When I use more than one of the CustomControl1 in my application and set value for each MyProperty

  <StackPanel HorizontalAlignment="Left" Orientation="Vertical" VerticalAlignment="Top" Width="176">
        <local:CustomControl1>          
            <local:CustomControl1.MyProperty>
                <System:String>A</System:String>
                <System:String>B</System:String>
                <System:String>C</System:String>
                <System:String>D</System:String>
            </local:CustomControl1.MyProperty>          
        </local:CustomControl1>
        <local:CustomControl1>          
            <local:CustomControl1.MyProperty>
                <System:String>F</System:String>
                <System:String>E</System:String>                    
            </local:CustomControl1.MyProperty>          
        </local:CustomControl1>
    </StackPanel>

when run solution , all values shown in each CustomControl1
and in design mode only show value of last customcontrol1.

So it looks as all of them share the same instance data.

  • 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-06-13T11:09:11+00:00Added an answer on June 13, 2026 at 11:09 am

    When creating a Dependency Property for a collection (List, Dictionary…) always reinitialize the DP in the class’s constructor.
    (Otherwise you’ll be using the same list for all instances)

    So in your case:

    public CustomControl1()
    {
        MyProperty = new List<string>();
    }
    

    and remove the value in the Dependency Property’s default value:

    public static readonly DependencyProperty MyPropertyProperty =
            DependencyProperty.Register("MyProperty", typeof(List<string>), 
                                                       typeof(CustomControl1), 
                                                       new UIPropertyMetadata(null));        
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom control with following: <TextBox Grid.Column=3 Text={TemplateBinding SampleValue} /> public static readonly
I have a custom control like this: public class CustomControl1 : Control { private
I have my custom control named FileSelectDialog with Dependency Property: public static readonly DependencyProperty
I'm attempting to create a CustomControl which will have various properties affected by an
I have defined following control template for my custom control. <ControlTemplate TargetType={x:Type local:CustomControl}> <Grid
I have a custom control with a public collection marked as DesignerSerializationVisibility.Content . When
I have a custom control that inherits from UserControl , and I can't get
I have a custom class named BlinkingLight. I also have a static ObservableCollection BlinkingLightCollection.
I need to implement a Ruler and I have a CustomControl RangeSlider which is
I have a WPF CustomControl that is derived from ComboBox and I'm trying to

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.