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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:39:24+00:00 2026-05-14T20:39:24+00:00

private TextBlock _caption = new TextBlock(); public TextBlock Caption { get { return _caption;

  • 0
private TextBlock _caption = new TextBlock();

public TextBlock Caption  
{  
    get { return _caption; }  
    set { _caption = value; }  
}

<l:CustomPanel>  
    <l:CustomPanel.Caption Text="Caption text" FontSize="18" Foreground="White" />  
</l:CustomPanel>

Gives me the following error:
Cannot set properties on property elements.

If I use:

<l:CustomPanel>  
    <l:CustomPanel.Caption>
        <TextBlock Text="Caption text" FontSize="18" Foreground="White" /> 
    </l:CustomPanel.Caption>
</l:CustomPanel>

My TextBlock shows up fine but it’s nested inside another TextBlock like so, it even seems to add itself outside of the Caption property:

<l:CustomPanel>  
    <l:CustomPanel.Caption>
        <TextBlock>
             <InlineUIContainer>
                 <TextBlock Text="Caption text" FontSize="18" Foreground="White" /> 
             </InlineUIContainer>
        </TextBlock>
    </l:CustomPanel.Caption>

    <TextBlock>
         <InlineUIContainer>
             <TextBlock Text="Caption text" FontSize="18" Foreground="White" /> 
         </InlineUIContainer>
    </TextBlock>
</l:CustomPanel>

As you might have already guessed, what i’d like my code to do is to set my Caption property from XAML on a custom panel, if this is possible.

I’ve also tried the same code with a DependencyProperty to no avail.

So, anyone that can help me with this problem?

  • 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-14T20:39:25+00:00Added an answer on May 14, 2026 at 8:39 pm

    I can explain what is going wrong and how to fix it.

    First,

    <l:CustomPanel>
      <l:CustomPanel.Caption Text="Caption text" FontSize="18" Foreground="White" />
    

    is a simple syntax error. The <l:CustomPanel.Caption> syntax does not accept XML attributes – the property value must be within the element.

    This is proper property element syntax:

    <l:CustomPanel>    
      <l:CustomPanel.Caption>  
        <TextBlock Text="Caption text" FontSize="18" Foreground="White" />   
      </l:CustomPanel.Caption>  
    </l:CustomPanel>
    

    but:

    1. Property element syntax works only with DependencyProperties (so it didn’t work with your CLR property) and
    2. Property element syntax always honors the ContentPropertyAttribute of the property type

    Since TextBlock has a [ContentPropertyAttribute(“Inlines”)], the property element syntax is trying to add the TextBlock to the Inlines collection.

    The solution is simple: Declare your property as a DependencyProperty of type UIElement instead of type TextBlock. This has the additional advantage of not restricting the display of content to just a TextBlock. If you really do want to restrict it to just a TextBlock, you can use a validation callback.

    public UIElement Content { get { ...
    public static readonly DependencyProperty ContentProperty = ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • 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 You can do this without any code: Go to Site… May 16, 2026 at 10:16 am
  • Editorial Team
    Editorial Team added an answer Can't speak to iPhone as I don't know enough about… May 16, 2026 at 10:16 am
  • Editorial Team
    Editorial Team added an answer Use the extend() function to add functions to the jQuery… May 16, 2026 at 10:16 am

Trending Tags

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

Top Members

Related Questions

I want to set the Text of a TextBlock in my StatusBar before making
In my view I have this: <TextBlock Text={Binding Title}/> which binds to my ViewModel's
I have set Private Memory limit of 200mb in IIS 7 for an application
I have the following Field: private IList<Modulo> modulos; and the following Property: public virtual
I have the following code: private SetMultimap<String, Dynamic> dynamicFields = TreeMultimap.create(Ordering.natural(), new Comparator<Dynamic>() {
I have a class as follows: public class Polygon extends Shape{ private int noSides;
I have a textblock that is bound to an object. This object I have
I am trying to make a private messaging system, where you send a message
Say I have a method declaration like: private void someMethod(final String someKey, final Object
In .NET, are private methods and properties enforced by the runtime or just by

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.