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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:48:36+00:00 2026-05-13T08:48:36+00:00

I am learning Silverlight. In the process, I’m trying to build a custom user

  • 0

I am learning Silverlight. In the process, I’m trying to build a custom user control. My ultimate goal is to be able to write the following statement in XAML:

<my:CustomControl>
  <my:CustomControl.MainControl>
    <Canvas><TextBlock Text="Hello!" /></Canvas>
  </my:CustomControl.MainContent>
</my:CustomControl>

The content of the control will be wrapped in a custom border. Once again, this is just a learning exercise. To append my border, I have create the following UserControl:

<UserControl x:Class="CustomControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">

    <Grid x:Name="LayoutRoot">
      <Border>
        <!-- CustomControl Content -->
      </Border>
    </Grid>
</UserControl>

The code-behind for this file looks like the following:

public partial class CustomControl : UserControl
{
  public UIElement MainContent
  {
    get { return (UIElement)GetValue(MainContentProperty); }
    set { SetValue(MainContentProperty, value); }
  }

  public static readonly DependencyProperty MainContentProperty =
    DependencyProperty.Register("MainContent", typeof(UIElement), typeof(CustomControl),  
    new PropertyMetadata(null));


  public CustomControl()
  {
    InitializeComponent();            
  }
}

The thing I am having a problem with is getting the MainContent to appear in my CustomControl. I am confident that I am setting it properly, but I’m not sure how to display it. I really want it to be a DependencyProperty as well so I can take advantage of data binding and animations.

How do I get the MainContent to appear in the CustomControl? Thank you

  • 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-13T08:48:36+00:00Added an answer on May 13, 2026 at 8:48 am

    First you need to wait until the rest of the control has been parsed so you need to hook the loaded event:-

    public CustomControl()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(CustomControl_Loaded);
    }
    

    Then in the loaded event assign your MainControl property to the Child property of the border. To do that its best if you give your Border an x:Name which for now I’ll simple call “border”.

    void CustomControl_Loaded(object sender, RoutedEventArgs e)
    {
        border.Child = MainControl;
    }
    

    That’ll get you going. Of course you may need to deal with the MainControl property being changed dynamically so you need add a bool isLoaded field in your control and set that in the loaded event. When true your MainControl setter should assign the incoming value to the border.Child.

    Things can start to get more complicated and in fact I don’t recommend this approach to creating a custom control. For a better approach see Creating a New Control by Creating a ControlTemplate

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

Sidebar

Ask A Question

Stats

  • Questions 290k
  • Answers 290k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Please note the following: I've assumed that there is a… May 13, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer I think it's as simple as this: $(thumbs).click(function() { var… May 13, 2026 at 5:50 pm
  • Editorial Team
    Editorial Team added an answer If you are allowing strangers to execute code on your… May 13, 2026 at 5:50 pm

Related Questions

Recently I just got assigned a project to develop a web application/site that uses
There's a lot to C# & ASP.net. Where should I start? What should I
I am learning Silverlight and WPF on my own to expand my programming base.
I am learning WPF / Silverlight and saw in an MS vidcast that it
I am a bit surprised that while learning WPF/XAML/Silverlight almost all of the XAML/C#

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.