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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:07:00+00:00 2026-05-10T23:07:00+00:00

I want to set the width of a TextBlock based on the width of

  • 0

I want to set the width of a TextBlock based on the width of its container, minus the margins set on the TextBlock.

Here is my code:

<TextBlock x:Name='txtStatusMessages'             Width='{Binding ElementName=LayoutRoot,Path=ActualWidth }'                    TextWrapping='WrapWithOverflow'             Foreground='White'             Margin='5,5,5,5'>This is a message </TextBlock> 

And that works great except for the fact that the TextBlock is 10 units too big due to the Left and Right Margins bbeing set to 5.

OK, so I thought… Let’s use a Converter. But I don’t know how to pass the ActualWidth of my container control (SEE ABOVE: LayoutRoot).

I know how to use converters, and even converters with parameters, just not a parameter like… Binding ElementName=LayoutRoot,Path=ActualWidth

For example, I can’t make this work:

Width='{Binding Converter={StaticResource PositionConverter},          ConverterParameter={Binding ElementName=LayoutRoot,Path=ActualWidth }}' 

I hope I made this clear enough and hope that you can help because Google is no help for me tonight.

  • 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. 2026-05-10T23:07:01+00:00Added an answer on May 10, 2026 at 11:07 pm

    you’re supposed to use the other control as the source, not the parameter. The parameter has to be a constant and in your case can be -5.

    I’m not near VS at the moment so the syntax maybe inaccurate, however, it is something like:

    Width='{Binding ElementName=LayoutRoot, Path=ActualWidth, Converter={StaticResource PositionConverter}, ConverterParameter=-5}' 

    (The converter will receive -5 as a string and will have to convert it into a number before using it.)

    From my experience it is better to use the OnXXXChanged callback of DependecyProperty XXX, and not bind controls within the same window/root control one to another. One of the reasons for this is that you may want to bind them to an external element later on.

    Or alternatively, use multibinding:

    <TextBlock>     <TextBlock.Width>         <MultiBinding Converter='{StaticResource yourConverter}'>             <MultiBinding.Bindings>                 <Binding /> <!-- Bind to parameter 1 here -->                 <Binding /> <!-- Bind to parameter 2 here -->           </MultiBinding.Bindings>         </MultiBinding>     </TextBlock.Width> </TextBlock> 

    and and a converter which converts the two parameters to the value you want.

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

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • 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 If you do handle them, how do you justify this… May 12, 2026 at 1:03 am
  • Editorial Team
    Editorial Team added an answer // this conditional is necessary if myType can be an… May 12, 2026 at 1:03 am
  • Editorial Team
    Editorial Team added an answer The InputMask property can contain up to three sections separated… May 12, 2026 at 1:03 am

Related Questions

I want to set the backgroun color for a GridViewColumn that is databound inside
I have a control bound to an Object and all is well but I
I can trigger property settings on my ListBoxItem template based on properties of underlying
I'm very new to Silverlight so I apologise if this question is obvious but

Trending Tags

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

Top Members

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.