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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:44:27+00:00 2026-05-12T08:44:27+00:00

I am making a Silverlight UserControl where the consumer of the control needs to

  • 0

I am making a Silverlight UserControl where the consumer of the control needs to be able to provide custom attributes and content. I thought this would be as easy as exposing my custom attributes as dependency properties and deriving from ContentControl, but apparently not.

Here are my questions regarding this:

  1. I got the attribute to work as a simple dependency property, but to bind it to the UI in the control itself, I had to set the DataContext of the control to its own class (this.DataContext = this). This felt dirty all over…is there a better way to do this?

  2. I can get the consumer of my custom control to compile with a Content child element, but I don’t know how to display this in the control itself. I was thinking that a ContentPresenter whose Content is bound to the Content in the current binding context, but that’s not working.

I’d like to get this to work, but I’m also interested in what the recommended/best practice is and why. I had a tough time googling these things.

  • 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-12T08:44:28+00:00Added an answer on May 12, 2026 at 8:44 am

    Note: i have no experience in silverlight, but in WPF i’d do the following

    Let’s say you have a control MyControl which derives from UserControl, with a property MyProperty. I think the prettiest is to define a ControlTemplate for your control:

    <UserControl.Template>
        <ControlTemplate TargetType="{x:Type SomeNamespace:MyControl}">
            <StackPanel>
                <TextBlock Text="{TemplateBinding MyProperty}"/>
                <ContentPresenter/>
            </StackPanel>
        </ControlTemplate>
    </UserControl.Template>
    

    With {TemplateBinding} you can quickly create (OneWay!) bindings to properties of your control, while you can still use the normal {Binding} syntax to bind to your actual DataContext.
    Placing a ContentPresenter in your ControlTemplate will automatically display whatever is in your Content Property.

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

Sidebar

Related Questions

Silverligh 4, VS 2010. Making a Custom Control. (Non just UserControl, but public class
I am making a phone application in Silverlight, Windows Mobile. I am able to
I would like to understand the general requirements for WPF/Silverlight layout for making it
I'm making a WebPart for SharePoint that will instantiate a Silverlight UserControl and feed
So I have this little problem making this to work: I have silverlight client
I am making an application in Silverlight 3.0. In that application i am using
I am making an application in silverlight 3.0 In that application i want to
I am making a RIA application using Silverlight and web services. The method of
I am making restful requests in my silverlight app, I want to get information
I am making a Progressbar as part of my Silverlight application that is triggered

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.