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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:07:22+00:00 2026-05-11T21:07:22+00:00

I’m new to Silverlight and I wanted to accomplish a relatively simple task:    Create

  • 0

I’m new to Silverlight and I wanted to accomplish a relatively simple task:
   Create a “panel” control that would display a heading and some child content.

I was able to get this work to a degree, but the placement of the XAML really confuses me.

On my page I use my control. This results in my panel being shown with a button in the child content area which is blue, with a 20px yellow heading at the top saying “Below is some content”.

<UserControl x:Class="SilverlightApplication9.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:SilverlightApplication9">
    <Grid Background="White">        
        <local:MyPanel Background="Blue">            
                <Button Width="50" Height="25" Content="Hello"></Button>            
        </local:MyPanel>    
    </Grid>
</UserControl>

My panel source code is simple, just:

public partial class MyPanel : ContentControl
{
    public MyPanel()
    {
        DefaultStyleKey = typeof(MyPanel);   
        InitializeComponent();         
    }
}

It’s a partial class, and there is an attached XAML file, which is where my confusion starts:

If I try placing my style/template code into the partial class XAML file, it seems to be ignored (my button is shown, but the other content like the colors and text is missing)

<ContentControl x:Class="SilverlightApplication9.MyPanel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:SilverlightApplication9">
    <ContentControl.Resources>
        <ResourceDictionary>
            <Style TargetType="local:MyPanel">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="local:MyPanel">
                            <Grid Background="Yellow">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="20" />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <TextBlock HorizontalAlignment="Center" Height="20" Grid.Row="0" Text="Below is some content"/>
                                <Grid Grid.Row="1" Background="LightBlue">
                                    <ContentPresenter />
                                </Grid>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </ContentControl.Resources>
</ContentControl>

However if I create a \Themes\generic.xaml file and paste in the same code, it works

<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:SilverlightApplication9"
  xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
  >
    <Style TargetType="local:MyPanel">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:MyPanel">
                    <Grid Background="Yellow">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="20" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <TextBlock HorizontalAlignment="Center" Height="20" Grid.Row="0" Text="Below is some content"/>
                        <Grid Grid.Row="1" Background="LightBlue">
                            <ContentPresenter />
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

I’m clearly missing something important about how resources or XAML files are processed or used in a project (I did not have any experience with WPF before Silverlight).

What am I doing wrong that is preventing me from just putting the panel’s template code into the panel’s xaml file? Are there some concepts regarding XAML and resources that I’m getting wrong?

  • 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-11T21:07:22+00:00Added an answer on May 11, 2026 at 9:07 pm

    David, you need to create a key for your style, and reference it in the panel via it’s Style property … it is a limitation of Silverlight, that it does not let you create “global” styles that apply to all elements of some type.

    This behaviour is different when you place the style in themes, as you noticed.

    Another alternative is to place the style in the ResourceDictionary of the panel itself and not the page/user control, but then you cannot reuse that style in other panels.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem is that the word this is 4 characters,… May 12, 2026 at 12:56 am
  • Editorial Team
    Editorial Team added an answer I think you need to specify a unit... $(".calloutL2Copy").css("height", tallestcopy… May 12, 2026 at 12:56 am
  • Editorial Team
    Editorial Team added an answer First i have to tell you that you can't use… May 12, 2026 at 12:56 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.