【问题标题】:ItemsWrapGrid and item stretch (uwp)ItemsWrapGrid 和项目拉伸 (uwp)
【发布时间】:2016-05-06 19:54:12
【问题描述】:

我创建了通用的 Windows 应用程序。我将 GridView 与 ItemsWrapGrid 一起使用。我需要水平拉伸项目。

这是我的测试代码:

<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>

这是我的代码:

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

这是我的结果:

最后一行的文字不是全部。如何显示全文?

【问题讨论】:

    标签: c# xaml win-universal-app windows-10


    【解决方案1】:

    尝试使用ItemsStackPanel 而不是ItemsWrapGrid

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

    【讨论】:

    • 这是工作,但我需要其他行为。如果有可用空间,我需要多于一列。我需要 ItemsWrapGrid。
    • 在那种情况下,我不确定。我认为你能做的最好的就是给 TextBlock 一个所需的 MinWidth 或 Width。
    • 我决定使用 ItemsStackPanel :)
    猜你喜欢
    • 2017-02-27
    • 2016-03-03
    • 2015-11-27
    • 1970-01-01
    • 2012-10-19
    • 1970-01-01
    • 2020-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多