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

Related Questions

in my ListBox ItemTemplate i want set TextBlock UnderLine. as fllow: <StackPanel x:Name=TaskContent_SP Orientation=Horizontal
I want to set the width of one particular textbox in my view. No
I want to set fixed column width, but when content (String) is longer than
I am using wxPython's HyperTreeList and I want to set the column width exactly
I am new to web-design. I want to set the page-width so that it
I have an image with height 173px and width 157px .I want to set
i want to set imagesize same with the content size of the scrollview after
I want to check whether or not a cookie is set with every page
So i have a UIScrollview with UIImageView set with a button, I want to
I want to set font size for frametitle with \setbeamerfont. How to set any

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.