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 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

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
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
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

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.