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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:42:05+00:00 2026-06-11T08:42:05+00:00

I have a custom UserControl in Silverlight which in all simplicity is composed of

  • 0

I have a custom UserControl in Silverlight which in all simplicity is composed of TextBlocks and TextBoxes. I have a hierarchy of class entities as follows:

  • Person is an abstract super class that contains the properties Name and Age
  • Man is a child of Person that adds the property FacialFeature
  • Woman is a child of Person that adds the property LastMenstruated and HasHymen

So:

  • a Person contains the properties Name and Age
  • a Man contains the properties Name, Age and FacialFeature
  • a Woman contains the properties Name, Age, LastMenstruated and HasHymen

What I want is for my UserControl to simply display the values of those properties like so:

if Person is of type Man:

Name : Mark
Age : 23
FacialFeature : Fully Shaved

or if Person is of type Woman:

Name : Jane
Age : 8
LastMenstruated : Never
HasHymen : Yes

Bear in mind this is a simplified example for the sake of my question.

What I want is for my UserControl to display different information and possibly display it differently depending on the run-time type of Person.

I have thought about creating the control in the code-behind using a switch statement that would switch on GetType(Person), but what I don’t like about this, is that the logic would be in the UserControl. I would like a solution that has the objects encapsulate their own display, so that if I add new types of Person, I don’t need to go back to the UserControl and add in a case for the new types, etc.

  • 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-11T08:42:06+00:00Added an answer on June 11, 2026 at 8:42 am

    Taking your male/female split as an example you need to bind the Visibilty of the elements to the object being displayed through a converter that takes a parameter:

    <TextBlock Visibility="{Binding SelectedPerson,
                            Converter={StaticResource GenderConverter},
                            ConverterParameter=Male)" />
    

    Then in your converter:

    public class GenderConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((value is Man && parameter == "Male") ||
                 value is Woman && parameter == "Female"))
                return Visibility.Visible;
            else
                return Visibility.Collapsed;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw NotImplementedException();
        }
    }
    

    This means that you don’t have to add arbitrary UI properties to your classes to get them to display how you want them to.

    I’m not 100% sure of the tests for the object type (I don’t have Silverlight 5 installed on this machine)

    More information on the IValueConverter interface can be found on the MSDN.

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

Sidebar

Related Questions

I have a custom base user control in silverlight. <UserControl x:Class=Problemo.MyBaseControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008
I have a custom UserControl which contains several TextBoxes with Validators. One TextBox with
I have a custom UserControl which has a DependencyProperty ItemTemplate of type DataTemplate. I
I have a custom usercontrol, which is basically a dropdownlist, prepopulated with values from
I have a custom usercontrol created by myself which belongs to mine baseControls elements.
I'm building a custom Silverlight UserControl which needs to listen to events using Preview/Tunneling,
How to Bring (form_x) to the front. I have a custom usercontrol which opens
I have a custom UserControl which tries to recreate auto-complete for a textbox. When
I have a class inheriting from UserControl, with a custom DependencyProperty. I put a
I have created a custom XAML UserControl class that I pass to the ShowDialog

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.