views:

1324

answers:

3

I mean, i have one of this controls and text inside one of it's columns. Usually if user changes column size, it's just cutting text. If I'm trying to use template with textblock or textbox and set TextWrapping="Wrap" inside of the template - it's really doesn't change anything. What's the way out?

*And yes, I searched before asking, and found similar questions on this site. But without answer ((( *

A: 

The following worked for me:

<ListView ItemsSource="{Binding Source={StaticResource MyItems}}">
    <ListView.View>
        <GridView>
            <GridViewColumn Width="50" Header="Column 1">
                <GridViewColumn.CellTemplate>
                    <DataTemplate x:Name="col1Template">
                        <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding Path=Column1Text}" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            ...
        </GridView>
    </ListView.View>
</ListView>

This caused the text in the first column to wrap onto multiple lines if the width of the column wasn't wide enough to show all of the text.

Andy
A: 

Andy, thx for answer, though I'm myself was thinking that it should act that way. I ckecked your simple variant and it works. Though I have a similar example and it didn't worked. The only difference was that in template I used my UserControl that have TextBlock and other controls inside the StackPanel inside it's Content Property. And after hour of experimenting with Width, HorizontalAlignment and so on in different part of the code I understand, that I can do nothing. And then - i just changed StackPanel with Grid. And - viola! - it works. I don't know if it's a bug or just some specific reaction of StackPanel (actually I checked it parameters in run-time - and it was very strange: ActualWidth was more then the DesiredSize and real width of the Panel). So if someone could tell me - why is this so? - it would be interesting. If no - i'll just use version with Grid.

Aks1
I think that one difference between StackPanel and Grid is that controls in a Grid expand to fill the maximum space (unless directed not to), while this is not the case with a StackPanel. I haven't come across a reason for this, just what I've seen from experimentation.
Andy
A: 

Make sure you don't have datagrid RowHeight defined or it is going to override the "true" height of the textblock after it has been textwrapped.

Epaphrodite Dusingizimana