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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:43:00+00:00 2026-05-20T01:43:00+00:00

Why won’t this work? In generic.xaml for a custom control: In the style applied

  • 0

Why won’t this work?

In generic.xaml for a custom control:

In the style applied to the custom control…

<Setter Property="ChromeContent">
  <Setter.Value>
    <Grid />
  </Setter.Value>
</Setter>

…

Later, in the control template…

<ContentPresenter Grid.Column="0" 
     x:Name="ChromeContentPresenter" 
     Content="{TemplateBinding ChromeContent}" />

Here’s the dependency property for ChromeContent…

public Object ChromeContent
{
  get { return (Object)GetValue(ChromeContentProperty); }
  set { SetValue(ChromeContentProperty, value); }
}
public static readonly DependencyProperty ChromeContentProperty =
    DependencyProperty.Register("ChromeContent", typeof(Object), 
    typeof(casPopup), null);

As you can see, it takes any object. I tried changing it to a Grid, but that did not help.

It throws this error (from javascript): _Failed to assign to property ‘System.Windows.Controls.ContentPresenter.Content’

Oddly, the following will work fine if I remove the Grid from the setter nd just use text:

<Setter Property="ChromeContent" Value="DEFAULT" />

Also, this will work too from the OnApplyTemplate method in the control class:

  Grid g = new Grid();
  g.Width = 100;
  g.Height = 25;
  g.Background = new SolidColorBrush(Colors.LightGray);
  ChromeContent = g;

I’m having a hard time understanding what is preventing the default content of a grid, defined in the generic.xaml from working. Does anyone have any knowledge on this matter?

Many thanks in advance for your help!

  • 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-20T01:43:01+00:00Added an answer on May 20, 2026 at 1:43 am

    This is the problem:-

    <Setter Property="ChromeContent">
      <Setter.Value>
        <Grid />
      </Setter.Value>
    </Setter>
    

    You should not include a UIElement directly in a resource dictionary or as a value of a style. You might see the style as being some kind of descriptor but it isn’t. The values in a style are constructed instances of the objects they hold. Your style holds a single instance of Grid. Whenever that style is used to assign to a ChromeContent property it will attempt to assing the same single instance of the Grid.

    A UIElement can only be a child of one parent. What would happen if two instances your control were constructed? There would (if silverlight let you) be an attempt to assign the same single instance of the Grid to both controls.

    This is one reason for templates such as ControlTemplate and DataTemplate. The markup inside these is invoked each time the template is used rather than when the Xaml is first parsed.

    Edit:

    To answer you supplementary question, you should default another property of type DataTemplate:-

    <Setter Property="ChromeContentTemplate">
      <Setter.Value>
        <DataTemplate>
          <Grid />
        </DataTemplate>
      </Setter.Value>
    </Setter>
    

    Property:-

    public Object ChromeContentTemplate
    {
      get { return (DataTemplate)GetValue(ChromeContentTemplateProperty); }
      set { SetValue(ChromeContentTemplateProperty, value); }
    }
    
    public static readonly DependencyProperty ChromeContentTemplateProperty=
        DependencyProperty.Register("ChromeContentTemplate", typeof(DataTemplate), 
        typeof(casPopup), null);
    

    Control Template:-

    <ContentPresenter Grid.Column="0" 
         x:Name="ChromeContentPresenter" 
         Content="{TemplateBinding ChromeContent}"
         ContentTemplate="{TemplateBinding ChromeContentTemplate" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This just won't work. The problem is that I do not know enough to
Why won't this simple subtraction work? int MyPageNumber = Convert.ToInt32(cboPageNumber.SelectedItem); MyPageNumber += (MyPageNumber -
This won't work using: $('div#menuBar,#goLeftBtn,#goRightBtn').attr('disabled', true); in the document.ready Any ideas? Thanks! EDIT: My
Why won't this work in Safari? <script language=javascript type=text/javascript> function changeUrl(url) { window.location.href='http://google.com'; return
Why won't this work? http://jsfiddle.net/PdwJ6/ HTML <a href=# id=showMore>Before</a> JS $('#showMore').click(function() { $(this).toggle( function
Why won’t this work? <html> <head> <title>Learning the basics of canvas</title> <meta charset=utf-8> <script
I know this won't be a popular question, because a lot of web designers
Any ideas why this won't validate here: http://validator.w3.org/#validate_by_input It seems the form input tags
I fail to understand why this code won't compile ExecutorService executor = new ScheduledThreadPoolExecutor(threads);
Won't the union in this question cause UB when used as this: union Data

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.