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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:07:12+00:00 2026-05-20T14:07:12+00:00

I’m working on a feature that will allow a user to click onto a

  • 0

I’m working on a feature that will allow a user to click onto a blank area (e.g. a Canvas) and add a span of text where they click. After they click, they can immediately edit the text, change the foreground, font size, etc. Kind of like adding a span of text to a PowerPoint slide.

I’m wondering what the best approach for such a control would be. My initial thought would be a custom control (inherit from Control) that has two internal TemplateParts: a TextBlock and a TextBox. I will have two visual states: Viewing and Editing. I’ll have a string dependency property on the custom control called Text that the two template parts are bound to on their own Text properties. When the user clicks on the control, it goes into Editing mode, the TextBlock is collapsed and the TextBox is visible. When the TextBox loses focus, the control goes into Viewing mode and the TextBlock becomes visible. When the user edits the text in Editing mode, the Text property is updated and all the bindings reflect the new Text value.

My concern with this approach is the number of bindable properties I’m going to have to wrap. For example, Control has Foreground, FontSize, and FontFamily properties. I want these properties to be carried into my two template part controls because they should reflect what the user wants to see at all times – both in Viewing and Editing mode. For example, setting Foreground=Red on the custom control means the internal TextBox and TextBlock should also have a Red foreground. Thus, I have to wire up the bindings in OnApplyTemplate for every property for both template parts:

public override void OnApplyTemplate(){ 

    // ... stuff ...

    var foregroundBinding = new Binding
    {
        Source = this,
        Path = new PropertyPath("Foreground")
    };

    myTextBox.SetBinding(TextBox.ForegroundProperty, foregroundBinding);
    myTextBlock.SetBinding(TextBlock.ForegroundProperty, foregroundBinding);

    // repeat for every other property, such as font size,
    // font family, width, maxwidth, height, maxheight,
    // horizontal alignment, yadda yadda yadda...
}

Given that there are possibly dozens of properties I’d want to transfer from my custom control to these internal template parts, this seems like a tedious approach that will be difficult to maintain – especially if I change my strategy for the template parts later on.

Is there a better approach, or am I on the right track here?

  • 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-20T14:07:13+00:00Added an answer on May 20, 2026 at 2:07 pm

    why do you need both, a TextBlock and a TextBox? From what you say, the TextBox alone would be enough. You would apply a style that has some triggers that change the looks depending on IsKeyboardFocused.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
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 a bunch of posts stored in text files formatted in yaml/textile (from
I need to clean up various Word 'smart' characters in user input, including but
I want use html5's new tag to play a wav file (currently only supported
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
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.