【发布时间】:2018-08-27 22:21:11
【问题描述】:
我正在开发一个 Windows 10 UWP 和一个 Windows Phone 8.1 项目。在项目中,有类似 Instagram 的标签,可以在图片中看到。这些标签使用 GridView 打印在屏幕上。问题是我无法通过它们的内容使 GridView 项目的宽度动态化。它采用第一个项目的宽度,并为所有其他项目提供相同的宽度。对于较短的单词,这不是问题,但较长单词的某些字母不可见。
这是问题的屏幕截图。
我写的代码;
<GridView SelectionMode="None" ItemsSource="{Binding TagsArray}" ScrollViewer.IsHorizontalRailEnabled="True">
<GridView.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock x:Name="tagButton" Tapped="tagButton_Tapped" FontWeight="Medium" Text="{Binding}" Foreground="#063076" FontSize="11" HorizontalAlignment="Left"/>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
<Setter Property="Margin" Value="0,-15,0,-15"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</GridView.ItemContainerStyle>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
【问题讨论】:
-
我完成了自己的 WrapGrid 的编写
标签: c# xaml uwp windows-phone-8.1 windows-10-mobile