This is a migrated thread and some comments may be shown as answers.

[Solved] Problem with text alignement in a GridView

11 Answers 157 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
fred
Top achievements
Rank 1
fred asked on 18 Jun 2010, 11:06 AM
Hello,

I'm starting to use the Silverlight environment.
I create a gridview in which I want to be able to center the text contained in each cell.
AND I want to specify a size of each column of the gridview (easily done) But the text contained in the cell should fill the cell making the cell grow in height by itself. (Not sure I am clear enough).

How can I do that ?  Thanks in advance.

here is my code : (I want the content of my QualityControlDescription variable to fill the cell and be fully visible)

<StormGridView:StormGridViewColumn Header="Description" TextAlignment="Center" HeaderTextAlignment="Center" Width="300">
                                    <StormGridView:StormGridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="{Binding Path=QualityControlDescription}" Margin="5" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" TextAlignment="Center">
                                                </TextBlock>
                                            </StackPanel>
                                        </DataTemplate>
                                    </StormGridView:StormGridViewColumn.CellTemplate>
                                </StormGridView:StormGridViewColumn>

11 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 18 Jun 2010, 11:32 AM
Hello fred,

Have you tried to turn on the text wrapping of the textblock ?

Kind regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
fred
Top achievements
Rank 1
answered on 18 Jun 2010, 12:20 PM
Hello Pavel,

Alas yes, I tried it, and as it didn't work I thought it wasn't the property I needed (seems it is tough, because of your message).
I just re-tried to put the TextWrapping="Wrap", but still, no effect on my cell content.
Do I need to specify another width ? Is there a more global property that could block this ?

Again, thanks in advance
0
Vlad
Telerik team
answered on 21 Jun 2010, 07:21 AM
Hello,

 This is caused by the StackPanel in your template since in this case the TextBlock will be measured with infinity. You can remove the StackPanel or specify width for the TextBlock.

I've attached an example application.

Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
fred
Top achievements
Rank 1
answered on 21 Jun 2010, 07:44 AM
It fixed my problem.

Thanks and have a good day.
0
Chris Evans
Top achievements
Rank 1
answered on 23 Aug 2010, 08:37 PM
Hello Telerik,

I have the same issue and I am able to get the same results you did in the example, however the scrollviewer doesn't appear when the text is extremely long, it just keeps stretching.  Could you modify the example to display say 2 lines and scroll the rest of the content, Thank you.
0
Milan
Telerik team
answered on 24 Aug 2010, 10:59 AM
Hi Chris Evans,

Which ScrollBar does not appear when you have a very long text?


Best wishes,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chris Evans
Top achievements
Rank 1
answered on 24 Aug 2010, 02:27 PM
I apologize if I didn't explain fully.  It is the vertical scrollviewer of the TextBox that does not appear when the text is long.  I tried setting Height and MaxHeight on the TextBox but that does not cause the vertical scrollviewer to work either.
0
Milan
Telerik team
answered on 24 Aug 2010, 02:40 PM
Hi Chris Evans,

I have used the following template and it seems to work fine.

<telerik:GridViewColumn.CellTemplate>
    <DataTemplate>
          
            <TextBox Text="{Binding Path=QualityControlDescription}" Margin="5"
                       TextWrapping="Wrap" MaxHeight="200"
                        HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible"
                       TextAlignment="Center">
            </TextBox>
          
    </DataTemplate>
</telerik:GridViewColumn.CellTemplate>


Greetings,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chris Evans
Top achievements
Rank 1
answered on 24 Aug 2010, 03:42 PM
Strange, that this does not work fine

<TextBlock Text="{Binding Path=QualityControlDescription}" Margin="5"    TextWrapping="Wrap" MaxHeight="40"                                   ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"                                TextAlignment="Center">  </TextBlock>


is there a way to make it work with a TextBlock or would it than be easier to template the TextBox?
0
Milan
Telerik team
answered on 24 Aug 2010, 04:03 PM
Hello Chris Evans,

The TextBlock controls does not have a built-in ScrollViewer and that is why no Scrollviewer is shown. If you need to have ScrollBars you can use a read only TextBox.


All the best,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chris Evans
Top achievements
Rank 1
answered on 25 Aug 2010, 02:38 PM
I was able to get this code to work



<
TeleGrid:GridViewDataColumn Header="Notes" Width="200" TextAlignment="Center" HeaderTextAlignment="Center" >
                                   <TeleGrid:GridViewDataColumn.CellTemplate>
                                       <DataTemplate>
                                           <ScrollViewer BorderThickness="0" MaxHeight="44" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" >
                                               <TextBlock x:Name="txtgridNote" TextWrapping="Wrap" TextAlignment="Center" Width="160" />
                                           </ScrollViewer>
                                       </DataTemplate>
                                   </TeleGrid:GridViewDataColumn.CellTemplate>
                               </TeleGrid:GridViewDataColumn>
 
Thank you
Tags
GridView
Asked by
fred
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
fred
Top achievements
Rank 1
Vlad
Telerik team
Chris Evans
Top achievements
Rank 1
Milan
Telerik team
Share this question
or