1

I created univeral windows app. I use GridView with ItemsWrapGrid. I need to stretch item by horizontal.

It is my test code:

<GridView x:Name="Test"
          AutomationProperties.AutomationId="ItemGridView"
          AutomationProperties.Name="Items In Group"
          IsItemClickEnabled="True"
          IsSwipeEnabled="False"
          ScrollViewer.VerticalScrollBarVisibility="Hidden"
          ScrollViewer.VerticalScrollMode="Disabled"
          SelectionMode="Single">

    <GridView.ItemContainerStyle>
        <Style TargetType="GridViewItem">
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="VerticalAlignment" Value="Stretch" />
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="VerticalContentAlignment" Value="Stretch" />
        </Style>
    </GridView.ItemContainerStyle>


    <GridView.ItemTemplate>
        <DataTemplate>

            <TextBlock MinWidth="100"
                       HorizontalAlignment="Stretch"
                       VerticalAlignment="Stretch"
                       Text="{Binding}"
                       TextWrapping="WrapWholeWords" />


        </DataTemplate>
    </GridView.ItemTemplate>

    <GridView.Transitions>
        <TransitionCollection>
            <EntranceThemeTransition />
        </TransitionCollection>
    </GridView.Transitions>
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsWrapGrid Orientation="Vertical" />
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
</GridView>

it is my code behinded:

        this.InitializeComponent();
        var items = new List<string>
        {
            "test",
            "test test",
            "test test 000 1111 test test 000 1111",
        };
        Test.ItemsSource = items;

it is my result:

enter image description here

the text of the last line is not all. How do I display the full text?

1 Answer 1

2

Try using ItemsStackPanel instead of ItemsWrapGrid.

<GridView.ItemsPanel>
     <ItemsPanelTemplate>
          <ItemsStackPanel Orientation="Vertical" />
     </ItemsPanelTemplate>
</GridView.ItemsPanel>
3
  • It is work, but I need other behavior. I need more than one column if there is free space. I need ItemsWrapGrid.
    – FetFrumos
    May 8, 2016 at 4:34
  • In that case, I'm not sure. I think the best you can do is give the TextBlock a desired MinWidth or Width.
    – Justin Lam
    May 9, 2016 at 4:01
  • I decided to use ItemsStackPanel :)
    – FetFrumos
    May 11, 2016 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.