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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:47:04+00:00 2026-05-28T03:47:04+00:00

Goal I have a WPF application that contain text inside a DataGrid . I

  • 0

Goal

I have a WPF application that contain text inside a DataGrid.
I want the text to wrap inside each cell.
I also want to set a MinWidth for each column and if it has to, the ScrollViewer should create the horizonatl scroll bar.
I never want a horizontal scroll bar to appear for the any of the cells or the DataGrid itself.
If the user resizes the window, the rows should grow or shrink to accommodate the text wrapping, but it shouldn’t allow the coulmns get so thin that they are no longer readable.

Problem

Right now, the text doesn’t wrap because it is in a scrollviewer.
I know of different ways that I can change this sample to get the text to wrap, but I can’t get it to act exactly how I want it, as mentioned above.

Simplified xaml

<Window x:Class="SampleApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SampleApp"
    Title="App" Height="350" Width="525">

    <Window.Resources>
        <Style x:Key="WrappingTextBlock" TargetType="TextBlock">
            <Setter Property="TextWrapping" Value="Wrap"/>
        </Style>
        <Style x:Key="WrappingTextBox" TargetType="TextBox">
            <Setter Property="TextWrapping" Value="Wrap"/>
        </Style>
    </Window.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Stuff ... />

        <MoreStuff ... />

        <Border Grid.Row="1" Grid.Column="1">
            <ScrollViewer>
                <StackPanel>    
                    <DataGrid HorizontalAlignment="Left" ItemsSource="{Binding AwesomeObject, Mode=TwoWay}" Margin="5" AutoGenerateColumns="False">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="#" Binding="{Binding Number, Mode=TwoWay}"/>
                            <DataGridTextColumn Header="Header" Binding="{Binding Data, Mode=TwoWay}"/>
                            <DataGridTextColumn MinWidth="50" Header="Long Text" Binding="{Binding SoMuchText, Mode=TwoWay}" ElementStyle="{StaticResource WrappingTextBlock}" EditingElementStyle="{StaticResource WrappingTextBox}"/>
                        </DataGrid.Columns>
                    </DataGrid>
                </StackPanel>
            </ScrollViewer>
        </Border>
    </Grid>
</Window>
  • 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-28T03:47:04+00:00Added an answer on May 28, 2026 at 3:47 am

    Try setting the Width of the Columns to “*”

     <Border Grid.Row="1" Grid.Column="1">
         <ScrollViewer>
             <StackPanel>
                 <DataGrid HorizontalAlignment="Left" ItemsSource="{Binding AwesomeObject, Mode=TwoWay}" Margin="5" AutoGenerateColumns="False">
                     <DataGrid.Columns>
                         <DataGridTextColumn Width="10*" Header="#" Binding="{Binding Number, Mode=TwoWay}"/>
                         <DataGridTextColumn Width="10*" Header="Header" Binding="{Binding Data, Mode=TwoWay}"/>
                         <DataGridTextColumn Width="50*" Header="Long Text" Binding="{Binding SoMuchText, Mode=TwoWay}" ElementStyle="{StaticResource WrappingTextBlock}" EditingElementStyle="{StaticResource WrappingTextBox}"/>
                     </DataGrid.Columns>
                 </DataGrid>
             </StackPanel>
         </ScrollViewer>
     </Border>
    

    This means that Column 1 will be minimum 10 length and growing
    This means that Column 2 will be minimum 10 length and growing
    This means that Column 3 will be minimum 50 length and growing

    You can play with the * resizing using percentages (.Number*) or lengths (Number*)

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

Sidebar

Related Questions

We have a WPF application that we want to convert to Silverlight. I understand
goal: I have the string 1234432144 I want to only replace the first 2
My ultimate goal is to have a menu that adds a class to the
I have the eventual goal of determining that a particular database on a particular
I am developing a simple WPF application without any auto layout. The goal is
I have a complex WPF control that for some reasons (ie. performance) is not
i have wpf application, a game of sudoku. I have a model and user
I am creating domain model. I have Goal ( something that user wants to
My WPF TabControl contains multiple TabItems. I want to visually alert users that data
I'm working with a project that is WPF and VB.net. I want to visually

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.