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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:54:16+00:00 2026-05-24T06:54:16+00:00

I’m following the instructions at this post: how to create Multiple user control that

  • 0

I’m following the instructions at this post: how to create Multiple user control that pointing single code behind file in silverlight 4

This is an example from my code.

public class MyCommonUserControl : UserControl
{
    public static DependencyProperty CustomProperty = DependencyProperty.Register(
        "CustomProperty", typeof(int), typeof(MyCommonUserControl));

     public int CustomProperty
     {
         get
         {  
             return (int)GetValue(TypeProperty);
         }
         set
         {
             SetValue(TypeProperty, value);
             Extension();
         }
     }

     public virtual void Extension()
     {
     }
}

public class FirstMyCommonUserControl : MyCommonUserControl 
{
     public FirstMyCommonUserControl()
     {
         InitializeComponent();
     }

     public override void Extension()
     {
         base.Extension();

         // Do something
     }
}

As you can see above, I’m using inheritance. This code works for me, because I’ve got several custom controls, one of them is FirstMyCommonUserControl class which is overriding the virtual method and I can add some stuff for this particular class. Then I do this:

    MyCommonUserControl A;
    int number;

    private void button1_Click(object sender, RoutedEventArgs e)
    {            
        switch (number)
        {
            case 1:
            case 2:
            case 3:
            case 4:
                A = new FirstMyCommonUserControl();
                A.CustomProperty = number;

                canvas1.Children.Add((FirstMyCommonUserControl)A);
                break;
            case 5:
            case 6:
            case 7:
            case 8:
                A = new AnotherMyCommonUserControl();
                A.CustomProperty = number;

                canvas1.Children.Add((AnotherMyCommonUserControl)A);
                break;
        }
    }

Each particular class needs to do something more in CustomProperty. I made it using virtual methods and overriding it. I don’t know if doing this is the best way.

  • 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-24T06:54:16+00:00Added an answer on May 24, 2026 at 6:54 am

    Properties can also be virtual, not only methods. So you could write something like

    public class MyCommonUserControl : UserControl
    {     
        public virtual int CustomProperty     
        {         
            get { return (int)GetValue(TypeProperty); }
            set { SetValue(TypeProperty, value); }
        }
    }
    
    public class FirstMyCommonUserControl : MyCommonUserControl 
    {
        public override int CustomProperty     
        {         
            get 
            { 
                // Do something
                return base.CustomProperty;
            }
            set 
            { 
                // Do something
                base.CustomProperty = value;
            }
        }
    }
    

    Although whether or not is this better is debatable.

    Also, there is no need for a cast in this expression of yours:

    canvas1.Children.Add((FirstMyCommonUserControl)A);
    

    You can just write:

    canvas1.Children.Add(A);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.