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

Related Questions

private final List<KeyListener> keyListeners= new CopyOnWriteArrayList<KeyListener>(); public void addKeyListener(KeyListener keyListener){ keyListeners.add(keyListener); } In the
private Context mContext; public Upload(Context context, DropboxAPI<?> api, String dropboxPath) { // We set
I need to change border background color based of the textblock text string value
I have Listbox: <ListBox x:Name=FriendsRequestList> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation=Horizontal> <StackPanel> <TextBlock Text={Binding FullName} Foreground=#FF316DCB/>
Consider the following ViewModel property: private string _slowProperty; public string SlowProperty { get {
I have a usercontrol: <Grid x:Name=LayoutRoot Background=White> <TextBlock Name=TextBlock1 Text=Text for></TextBlock> </Grid> It has
private String setDate(int day) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DATE, + day);
private TextBox txtBoxDragPoint = new TextBox(); private void rtbLogicCode_MouseDown(object sender, MouseEventArgs e) { if
private void getSelectedTime(final String json){ Calendar now = Calendar.getInstance(); int year = now.get(Calendar.YEAR); int
private void SaveAsPicture_Click(object sender, RoutedEventArgs e) { WriteableBitmap bmp = new WriteableBitmap(MyUIElement, null); var

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.