简体   繁体   中英

ItemsWrapGrid and item stretch (uwp)

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:

在此处输入图片说明

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

Try using ItemsStackPanel instead of ItemsWrapGrid .

<GridView.ItemsPanel>
     <ItemsPanelTemplate>
          <ItemsStackPanel Orientation="Vertical" />
     </ItemsPanelTemplate>
</GridView.ItemsPanel>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM