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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:36:41+00:00 2026-06-11T15:36:41+00:00

I’m pretty new with WPF, so apologies if I’m missing something obvious. I have

  • 0

I’m pretty new with WPF, so apologies if I’m missing something obvious. I have this template that is bound to items in an obs. collection. I’m trying to get it so that the 2nd column, the “test test…” part has a variable width that fills all the available space in the parent grid.

What I’m finding though, is that my code automatically shows all the text for that “test test…” text box as opposed to just binding to the available space in the grid, and instead creates the scroll bar that you see below.

enter image description here

I instead, want that “test test” to be cut off so that everything else fits so that no scroll bar appears (that when, if the user resizes the screen then that “test test…” textbox will automatically resize to fit the new space). Is there a way to do that?

My code for that template is as follows:

            <DataTemplate x:Key="MainTemplate">
            <Grid Margin="4" ClipToBounds="True">
                <Grid.Resources>
                    <local:BooleanToHiddenVisibility x:Key="boolToVis"/>
                </Grid.Resources>
                <StackPanel Orientation="Vertical" ClipToBounds="True">
                    <Grid Width="Auto" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="25"/>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition Width="40" />
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition Width="40" />
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition Width="40" />
                            <ColumnDefinition Width="40" />
                        </Grid.ColumnDefinitions>
                        <CheckBox Grid.Column="0" Name="checkViewTextBox"/>
                        <TextBlock Grid.Column="1" Text="{Binding OriginalQuote}" FontWeight="Bold" TextTrimming="WordEllipsis" FontStyle="Italic" ClipToBounds="True"/>

                        <TextBlock Margin="10,0,0,0" Grid.Column="2"  Text="plane :" FontWeight="SemiBold" Width="60"/>
                        <TextBlock Margin="5,0,0,0" Grid.Column="3" Text="{Binding Mid}" Width="40"/>

                        <TextBlock Margin="10,0,0,0" Grid.Column="4"  Text="data2 :" FontWeight="SemiBold" Width="60"/>
                        <TextBlock Margin="5,0,0,0" Grid.Column="5" Text="{Binding MidTwo}" Width="40"/>

                        <TextBlock Margin="10,0,0,0" Grid.Column="6"  Text="data3:" FontWeight="SemiBold" Width="60"/>
                        <TextBlock Margin="5,0,0,0" Grid.Column="7" Text="{Binding MidThree}" Width="40"/>

                        <Button Margin="10,0,0,0" Content="History" Grid.Column="8" Click="History_Click" Width="40"/>
                    </Grid>

                    <StackPanel Orientation="Horizontal" Visibility="{Binding Path=IsChecked, ElementName=checkViewTextBox, Converter={StaticResource boolToVis}}">
                        <StackPanel.Resources>
                            <Style BasedOn="{StaticResource tbstyle}" TargetType="{x:Type TextBlock}" />
                        </StackPanel.Resources>
<!--Other stuff thats working ok-->

                </StackPanel>
            </Grid>
        </DataTemplate>

Any help is much appreciated!

P.S. I’ve been adding random proprieties hoping one will work, so if looks like I have random things on there, that’s probably why….

  • 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-06-11T15:36:42+00:00Added an answer on June 11, 2026 at 3:36 pm

    Well, not sure it will help you but some words about WPF layout.

    It has two steps: measure and arrange.

    At the first stage, the control tries to calculate its desired state. StackPanel asks its children about their desired sizes. It does not limit their size. (TextBlock with the binding to OriginalQoute has no explicitly set width!)

    At the second stage, control is arranged.
    Stack panel is allowed to occupy the whole left space of the column but it arranges its children as if its size was unlimited, so TextBlock shows the text completely.

    The question is how to limit the size of the TextBlock?

    Try binding

    <TextBlock Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=StackPanel}, Path=ActualWidth}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.