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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:10:18+00:00 2026-06-12T22:10:18+00:00

I have a DataGridTextColumn ElementStyle as follows: <DataGridTextColumn.ElementStyle> <Style TargetType={x:Type TextBlock}> <Style.Setters> <Setter Property=Background>

  • 0

I have a DataGridTextColumn ElementStyle as follows:

        <DataGridTextColumn.ElementStyle>
            <Style TargetType="{x:Type TextBlock}">
                <Style.Setters>
                    <Setter Property="Background">
                        <Setter.Value>
                            <LinearGradientBrush>
                                <GradientStop Color="Black" Offset="0" />
                                <GradientStop Color="White" Offset="2" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Foreground" Value="White" />
                    <Setter Property="TextWrapping" Value="Wrap" />
                </Style.Setters>
            </Style>
        </DataGridTextColumn.ElementStyle>

I will need a cell in this column to display text in multiple lines but the number of lines should not exceed 3. The TextBlock does not have a MaxLines property so I cannot specify it directly. What’s more the TextBlock does not have a Template property so I can’t use a border less, read-only TextBox either. What can I do 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-06-12T22:10:19+00:00Added an answer on June 12, 2026 at 10:10 pm

    Well I think the most simple way to achieve this is to use a TemplateColumn. Here is a quick sample : Second Column is a TextColumn where you can’t do much, first column is a TemplateColumn with a TextBox that will be borderless and readonly, and MaxLines set to 3 :

    <DataGrid>
        <DataGrid.Columns>
    
            <DataGridTemplateColumn Header="Template Column" Width="30" >
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox IsReadOnly="True" BorderThickness="0" Text="{Binding Mode=OneWay}" MaxLines="3" TextWrapping="Wrap" Foreground="White">
                            <TextBox.Background>
                                <LinearGradientBrush>
                                    <GradientStop Color="Black" Offset="0" />
                                    <GradientStop Color="White" Offset="2" />
                                </LinearGradientBrush>
                            </TextBox.Background>
                        </TextBox>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
    
            <DataGridTextColumn Header="Text Column" Binding="{Binding}" Width="30" >
                <DataGridTextColumn.ElementStyle>
                    <Style TargetType="{x:Type TextBlock}">
                        <Style.Setters>
                            <Setter Property="Background">
                                <Setter.Value>
                                    <LinearGradientBrush>
                                        <GradientStop Color="Black" Offset="0" />
                                        <GradientStop Color="White" Offset="2" />
                                    </LinearGradientBrush>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Foreground" Value="White" />
                            <Setter Property="TextWrapping" Value="Wrap" />
                        </Style.Setters>
                    </Style>
                </DataGridTextColumn.ElementStyle>
            </DataGridTextColumn>
        </DataGrid.Columns>
    
        <sys:String>coucouuuuuuuuuuuuu</sys:String>
    
    </DataGrid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: <DataGridTextColumn IsReadOnly=True Header=StringLock Binding={Binding StringLock}> <DataGridTextColumn.ElementStyle> <Style TargetType={x:Type TextBlock}>
I have a datagrid in wpf, my cell is <DataGridTextColumn.CellStyle> <Style TargetType=DataGridCell> <Setter Property=Background
i have a textBox(txtSearch) placed in a DataGridColumnHeadertemplate like this: <UserControl.Resources> <Style x:Key=DataGridColumnHeaderStyle1 TargetType={x:Type
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have the following code: <DataTemplate> <!--<sdk:DataGridTextColumn Binding={Binding Description} Header=Description Width=205 />--> <TextBlock Text={Binding
I have a DataGrid bound to a ViewModel's property of type ObservableCollection. Inside DataGrid
I have a WPF DataGrid with DataGridTextColumn <DataGridTextColumn Header=Grouping Binding={Binding Value.GroupIndexPlusOne, UpdateSourceTrigger=Explicit, Converter={StaticResource StringToIntConverter}}
I have a binding that works. The GUI updates. <DataGridTextColumn Binding={Binding Path=Value, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True,
I have a column defined like this: <DataGridTextColumn Binding={Binding Path=FileSizeBytes, Mode=OneWay} Header=Size IsReadOnly=True />
I have a datagrid biding to nullable properties. For null values in DataGridTextColumn, instead

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.